[Mono-list] Patch for bugzilla 31265, plus some pthreads

Tim Haynes thaynes@openlinksw.com (Tim Haynes)
Mon, 14 Oct 2002 09:48:55 +0100


Dick Porter <dick@ximian.com> writes:

> On Fri, 2002-10-11 at 15:32, Tim Haynes wrote:
>> Also, there was a mono_thread_create, but no mono_thread_attach for
>> existing threads). Have copied the mono_thread_create and replaced a
>> call t pthread_create() with pthread_self(), which works. There is a
>> callback to be called on unhandled exception for example, which now can
>> call a user-registerable callback or the original callback (calling
>> pthread_exit). The code in the user callback
>> mono_thread_attach_aborted_cb should do a longjmp to unwind the stack to
>> a frame above any Mono frames.
>
> Could you explain why this code is needed?

Suppose an already multithreaded program needs to host the Mono runtime. In
order to issue mono calls from an exitsing thread it needs a mono
environment (usually setup by mono_jit_init). 
But since mono jit_init can only be called once per process, it has to
create the environment somehow (or it should create a new thread by calling
mono_thread_create, pass the info to its start function and wait for it -
but just imagine what it would be like if we create/wait/destry a pthread
for each operation!). That's where the mono_thread_attach comes in handy.

Cheers,

~Tim
-- 
Product Development Consultant
OpenLink Software
Tel: +44 (0) 20 8681 7701
Web: <http://www.openlinksw.com>
Universal Data Access & Data Integration Technology Providers