[Mono-list] pthreads in mono

Paolo Molaro lupus at ximian.com
Fri Mar 28 13:21:48 EDT 2008


On 03/28/08 Chris Howie wrote:
> Note that it's not that simple though.  The signature specifies a
> pthread_t*, not a pthead_t**.  It wants a pointer to a structure that
> will be filled in, not a pointer to a pointer (as is IntPtr&).  The
> code as writted above will certainly corrupt the memory next to the
> location that the "handler" local is stored in, unless
> sizeof(pthread_t) is <= IntPtr.Size.

Sure and my code is correct and won't generate any memory corruption
because all the sane operating systems have pthread_t as an integer or a
pointer. You're free to look for an operating system where the above is
incorrect. When you have found it (you might need to write you own, as
even OSX got this bit right...) you will have to port mono to it first.

The reason the C++ code posted did a new pthread_t is possibly that by
default people like to waste memory and they allocated it on the heap.
It can be a simple local value as in my sample or a static/instance
field somewhere, as long as it is valid for when you need to remove the
callback it's fine.

lupus

-- 
-----------------------------------------------------------------
lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better


More information about the Mono-list mailing list