good chemistry is complicated,
and a little bit messy -LW
[Win32] pthreads and memory allocationby syphilis (Chancellor)
|on Nov 22, 2011 at 02:50 UTC||Need Help??|
syphilis has asked for the
wisdom of the Perl Monks concerning the following question:
Here is the Inline::C demo, based on the wikipedia example program. It runs fine for me on Cygwin, but never gets beyond the malloc call on native Win32 - where I'm using perl-5.12.0 and mingw.org's port of gcc-4.5.2 (which ships with the pthread library included).
Note that I'm allocating with 'malloc'. Re-allocating with 'realloc' produces the same problem, as does using 'Newx' or 'Renew' instead of the standard C functions.
As is, on Win32 that outputs:
at which point it crashes. (Irrespective of how many threads I specify it always crashes when *all* threads have reached the stage of having to allocate the memory.)
If I comment out the s = (char*) malloc(100); it outputs the expected:
Does anyone have some advice as to how I might successfully allocate memory inside the 'TaskCode' function on Win32 ?
(I'm also interested to hear any theories that explain the behaviour I'm seeing.)