Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: threads->create() blocks on Windows

by bulk88 (Priest)
on Mar 18, 2014 at 02:50 UTC ( #1078718=note: print w/ replies, xml ) Need Help??


in reply to threads->create() blocks on Windows

I see you earlier asked in #win32. In your script

use strict; use warnings; use threads; use IO::Socket::INET; my $s = IO::Socket::INET->new(PeerAddr => 'localhost', PeerPort => 80, Proto => 'tcp') or die "error: $@"; print "create t1\n"; my $t1 = threads->create(sub { my ($r) = @_; my $data = ''; print "in t1\n"; # this intentionally blocks. if this line is removed the p +roblem vanishes $r->recv($data, 64); print "recv done\n"; }, $s); print "create t2\n"; my $t2 = threads->create(sub { print "in t2\n"; # problem: this is never printed }, 0); print "done\n"; # problem: this is never printed, as threads->crea +te never returns $t1->join(); $t2->join();


Your code freezes like this.

Parent thread.
ntdll.dll!_KiFastSystemCallRet@0() ntdll.dll!_NtQueryVolumeInformationFile@20() + 0xc kernel32.dll!_GetFileType@4() + 0x72 > msvcr71.dll!_fstati64(int fildes=3, _stati64 * buf=0x0012fab4) L +ine 97 + 0x8 C perl519.dll!PerlLIOFileStat(IPerlLIO * piPerl=0x00cdc134, int han +dle=3, _stati64 * buffer=0x0012fab4) Line 971 + 0xe C perl519.dll!PerlIOUnix_setfd(interpreter * my_perl=0x00000400, _P +erlIO * * f=0x0012f9cc, int fd=1029, int imode=0) Line 2571 + 0x15 + C perl519.dll!PerlIOUnix_dup(interpreter * my_perl=0x00b4b014, _Per +lIO * * f=0x00b4bac4, _PerlIO * * o=0x00905b24, clone_params * param= +0x0012fb9c, int flags=1) Line 2696 + 0xf C perl519.dll!PerlIOBase_dup(interpreter * my_perl=0x00b4b014, _Per +lIO * * f=0x00b4bac4, _PerlIO * * o=0x008f5574, clone_params * param= +0x0012fb9c, int flags=1) Line 2221 C perl519.dll!PerlIO_fdupopen(interpreter * my_perl=0x0012f9cc, _Pe +rlIO * * f=0x00070023, clone_params * param=0x0012fb9c, int flags=1) + Line 503 + 0x13 C perl519.dll!Perl_fp_dup(interpreter * my_perl=0x00b4b014, _PerlIO + * * const fp=0x008f5574, const char type=0, clone_params * const par +am=0x0012fb9c) Line 11825 + 0xb C perl519.dll!PerlIO_clone(interpreter * my_perl=0x0000006c, interp +reter * proto=0x00000400, clone_params * param=0x0012fb9c) Line 617 ++ 0xc C perl519.dll!perl_clone_using(interpreter * proto_perl=0x0036471c, + unsigned long flags=6, IPerlMem * ipM=0x00000000, IPerlMem * ipMS=0x +00cdc028, IPerlMem * ipMP=0x00cdc044, IPerlEnv * ipE=0x00cdc060, IPer +lStdIO * ipStd=0x00cdc098, IPerlLIO * ipLIO=0x00cdc134, IPerlDir * ip +D=0x00cdc19c, IPerlSock * ipS=0x00cdc1c8, IPerlProc * ipP=0x00cdc278) + Line 13649 C perl519.dll!perl_clone_host(interpreter * proto_perl=0x0036471c, +unsigned long flags=6) Line 360 C threads.dll!S_ithread_create(interpreter * parent_perl=0x00000400 +, sv * init_function=0x008fcc14, long stack_size=0, int gimme=2, int +exit_opt=0, int params_start=3, int num_params=1) Line 794 C threads.dll!XS_threads_create(interpreter * my_perl=0x00000002, c +v * cv=0x0096de44) Line 1100 + 0x30 C perl519.dll!Perl_pp_entersub(interpreter * my_perl=0x00000000) L +ine 2794 C perl519.dll!Perl_runops_standard(interpreter * my_perl=0x0036471c +) Line 42 + 0x4 C perl519.dll!S_run_body(interpreter * my_perl=0x0000006c, long old +scope=1) Line 2449 + 0xa C perl519.dll!perl_run(interpreter * my_perl=0x0036471c) Line 2365 + + 0x8 C perl519.dll!RunPerl(int argc=2, char * * argv=0x01362478, char * +* env=0x00362d80) Line 259 + 0x6 C perl.exe!mainCRTStartup() Line 398 + 0xe C kernel32.dll!_BaseProcessStart@4() + 0x23
Child thread
ntdll.dll!_KiFastSystemCallRet@0() ntdll.dll!_ZwDeviceIoControlFile@40() + 0xc mswsock.dll!_WSPRecv@36() + 0xd1 mswsock.dll!_WSPRecvFrom@44() + 0xe099 ws2_32.dll!_recvfrom@24() + 0x87 > perl519.dll!win32_recvfrom(unsigned int s=3, char * buf=0x00b376f +4, int len=64, int flags=0, sockaddr * from=0x0117fa10, int * fromlen +=0x0117fe50) Line 481 + 0x34 C perl519.dll!PerlSockRecvfrom(IPerlSock * piPerl=0x00aad5e0, unsig +ned int s=3, char * buffer=0x00b376f4, int len=64, int flags=0, socka +ddr * from=0x0117fa10, int * fromlen=0x0117fe50) Line 1389 + 0x17 + C perl519.dll!Perl_pp_sysread(interpreter * my_perl=0x00000400) Li +ne 1699 C perl519.dll!Perl_runops_standard(interpreter * my_perl=0x0090865c +) Line 42 + 0x4 C perl519.dll!Perl_call_sv(interpreter * my_perl=0x00158018, sv * s +v=0x003b92b0, volatile long flags=18348252) Line 2764 + 0xc C threads.dll!S_ithread_run(void * arg=0x00905c24) Line 520 + 0x14 + C kernel32.dll!_BaseThreadStart@8() + 0x37
Using Process Explorer, which can give a kernel side stack dump (but its HIGHLY INACCURATE since I've never figured out how to make Proc Exp use symbol files).
ntoskrnl.exe!ZwAlertThread+0x28 ntoskrnl.exe!SeAssignSecurityEx+0x13f ntoskrnl.exe!MmGrowKernelStack+0x61a ntoskrnl.exe!IoPageRead+0xaf0 ntoskrnl.exe!MmGrowKernelStack+0x659 ntoskrnl.exe!RtlGenerate8dot3Name+0x1ca ntoskrnl.exe!IoCheckFunctionAccess+0xf841 ntoskrnl.exe!ZwSetSystemInformation+0x23 ntdll.dll!KiFastSystemCallRet MSVCR71.dll!fstati64+0x63 perl519.dll!win32_stderr+0x302 perl519.dll!PerlIO_teardown+0x3ea perl519.dll!PerlIOBase_dup+0x33 perl519.dll!PerlIO_allocate+0x8b perl519.dll!Perl_fp_dup+0x32 perl519.dll!perl_clone_using+0x74f perl519.dll!perl_clone_host+0x6f threads.dll+0x2647
IDK why a GetFileType on a socket while its doing a recv in another thread blocks the GetFileType. If I kill the child OS thread doing the recv (and therefore the ithread with it), the GetFileType/NtQueryVolumeInformationFile unblocks and execution in the parent thread continues.


Comment on Re: threads->create() blocks on Windows
Select or Download Code
Re^2: threads->create() blocks on Windows
by photron (Novice) on Mar 20, 2014 at 12:39 UTC
    Yes, I asked this on #win32 with a slightly different example. The problem is the same in both. As you showed in the traces, the blocking recv() blocks the duplication of the socket for the new thread t2. So I have to avoid this order of execution. Thanks for the hints, hopefully I can modify the program in the correct way to make it work :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1078718]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-09-17 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (99 votes), past polls