[M3devel] pthreads tls initialization?

Tony Hosking hosking at cs.purdue.edu
Thu Mar 19 00:22:59 CET 2009


The setspecific call is to initialize the handler stack to nil.  It is  
needed.

On 19 Mar 2009, at 01:33, Jay wrote:

>
> http://www.opengroup.org/onlinepubs/000095399/functions/pthread_key_create.html
>
>
> says that thread locals start as zero, but ThreadPThread.m3 does:
>
>
> PROCEDURE InitHandlers () =
>  BEGIN
>    WITH r = pthread_key_create_handlers() DO  END;
>    WITH r = pthread_setspecific_handlers(NIL) DO  END;
>    initHandlers := FALSE;
>  END InitHandlers;
>
>
> Any reason for that setspecific call?
>
>
> I ask because I think some of this code should just be written in C.
> But ideally then, the Win32 code should be too.
> So I'm just reading them, and they differ oddly in that pthread  
> keeps doing like:
>
>
> if not initialized Initialize()
>
>
> and Win32 allocates its thread up front locals via the Modula  
> initializer.
> Maybe pthread_key is very expensive, and avoided in single threaded  
> apps?
> But there aren't any, right, because the runtime creates threads, at  
> least one for the garbage collector?
>
>
> - Jay




More information about the M3devel mailing list