[Mono-list] pthreads in mono
Chris Howie
cdhowie at gmail.com
Fri Mar 28 11:42:03 EDT 2008
On Fri, Mar 28, 2008 at 8:10 AM, Paolo Molaro <lupus at ximian.com> wrote:
> The pointer is the one you got with gps_set_callback, so you can just
> ignore the fact that it is a pthread_t pointer and all this thread that
> went ballistic on that:
>
> [DllImport("gps")]
> static extern int gps_set_callback (IntPtr gps_data, GpsCallback cb, out IntPtr handler);
>
> ...
>
> IntPtr handler;
> IntPtr gps = gps_open ("localhost", "2947");
> gps_set_callback (gps, mycb, out handler);
> ...
>
> lupus
Ah, it *creates* a thread. That is a detail I missed when reading the manpage.
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.
So there are a basically two options: declare a struct matching the
pthread_t struct, or create a new byte[] of some size reasonably large
enough to contain a pthread_t and pass that off to the function.
--
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers
More information about the Mono-list
mailing list