[M3devel] thread calls on non-modula3 threads, win32 vs. posix
Jay K
jay.krell at cornell.edu
Sun Sep 26 14:21:51 CEST 2010
I think it is problematic in both.
If I understand you.
The thread locals could be allocated on-demand which might
address some situations. Though that can also fail.
A reasonable seeming place to allocate thread locals is m3core.DllMain(thread attach).
That even allows you to fail (due to low memory).
However that doesn't work as well as one might hope.
In particular, any number of threads can be created before a particular .dll is loaded.
And a .dll can be unloaded while the threads still exist -- making also thread detach
not so ideal for freeing. What you have to do is:
- be willing to allocate on demand
- have some story for failure
- track all the thread locals through a global (!) and free them in thread/process detach
(but note that there are two .dll unload scenarios: FreeLibrary and ExitProcess;
there is a parameter that distinguishes them; best to do nothing, quickly in
the ExitProcess).
Best really really really really best to avoid thread locals.
But that is probably impossible.
Cygwin does wacky stuff where it puts its thread locals at the top of the stack.
Which doesn't solve the problems.
- Jay
----------------------------------------
> From: hosking at cs.purdue.edu
> Date: Sat, 25 Sep 2010 10:32:21 -0400
> To: jay.krell at cornell.edu
> CC: m3devel at elegosoft.com
> Subject: Re: [M3devel] thread calls on non-modula3 threads, win32 vs. posix
>
> Is it ok in the WIn32 implementation for the thread to be native.
> I think it is ok for pthread.
>
> On 25 Sep 2010, at 05:35, Jay K wrote:
>
> >
> > PROCEDURE AlertWait (m: Mutex; c: Condition) RAISES {Alerted} =
> > (* LL = m *)
> > VAR self := GetActivation();
> > BEGIN
> > IF DEBUG THEN ThreadDebug.AlertWait(m, c); END;
> > IF self = NIL THEN Die(ThisLine(), "AlertWait called from non-Modula-3 thread") END;
> > XWait(m, c, self, alertable := TRUE);
> > END AlertWait;
> >
> >
> > The pthread code doesn't have the check for NIL and call to Die.
> > Nor for that matter, the uses of ThreadDebug -- which I added.
> >
> > I think these should be more similar.
> >
> > What I was really wondering about, again, is more common code between Win32 and Posix
> > in the thread code...
> >
> > - Jay
> >
>
More information about the M3devel
mailing list