[M3devel] User-level threading

Tony Hosking hosking at cs.purdue.edu
Mon Jul 16 14:47:08 CEST 2007


Mixed systems are difficult to get working properly (because of  
interactions between system and user scheduling), and usually result  
in more trouble than they are worth (witness discussions on this  
subject regarding Jikes RVM).  The difficulties are particularly  
pronounced with preemptive scheduling where system thread switches  
can occur at any time.  My inclination is to implement the user-level  
threading properly using setcontext, etc., instead of setjmp/ 
longjmp.  I will probably get to this next on my list of tinkering  
tasks with CM3.  Right now, I want to finish off my LONGINT  
implementation (grappling with the compiler as we speak) as well as  
the GC issue you reported.

On Jul 16, 2007, at 12:50 AM, Mika Nystrom wrote:

> Olaf Wagner writes:
>> On Wed, Jul 04, 2007 at 04:12:47PM -0400, Tony Hosking wrote:
>>> In looking at things again, I am more and more convinced that
>>> ThreadPosix should be implemented against the standard API for
>>> makecontext/getcontext/setcontext/swapcontext.  Platforms that do  
>>> not
>>> provide these will need to provide an equivalent implementation of
>>> these routines, similar to what you suggest.  Right now, I know  
>>> all of
>>> SOLgnu, I386_DARWIN, LINUXLIBC6, FreeBSD should have the necessary
>>> support.
>>
>> I think a `standard' implementation using makecontext/getcontext/...
>> would be the best. For those platforms that do not support that,
>> we can still use a C or assembler implementation.
>>
>> I would strongly vote for keeping user-level threading, too.
>
> Wouldn't the ideal be to have a mixed system, where N user-level  
> threads
> run inside M <= N, M \approx NCPUS Pthreads?
>
> Anyone who thinks user-level threads are unnecessary should try the
> following program, which runs just fine under user-level threads
> on FreeBSD, and locks up horrendously after running about 4% of the
> way on Darwin/Pthreads...
>
>      Mika
>
> MODULE Main;
> IMPORT Thread;
> IMPORT Rd, Stdio, Wr, Random, Fmt;
>
> TYPE Cl = Thread.Closure OBJECT OVERRIDES apply := A END;
>
>
> PROCEDURE A(cl : Cl) : REFANY =
>   VAR rand := NEW(Random.Default).init();
>   BEGIN
>     LOOP Thread.Pause(rand.longreal(1.05d0,1.15d0)); Wr.PutText 
> (Stdio.stdout,"."); Wr.Flush(Stdio.stdout) END
>   END A;
>
> CONST Nthreads=10000;
> BEGIN
>   FOR i := 1 TO Nthreads DO
>     Wr.PutText(Stdio.stdout, Fmt.Int(i) & "...\n"); Wr.Flush 
> (Stdio.stdout);
>     EVAL Thread.Fork(NEW(Cl))
>   END;
>
>   LOOP
>     WITH c = Rd.GetChar(Stdio.stdin) DO
>       IF c = 'q' THEN EXIT END
>     END
>   END
> END Main.
>
>>
>> Olaf
>> -- 
>> Olaf Wagner -- elego Software Solutions GmbH, Ohmstr. 9, 10179  
>> Berlin, Germany
>> phone: +49 30 23 45 86 96  mobile: +49 177 23 45 869  fax: +49 30  
>> 23 45 86 95
>> http://www.elegosoft.com  |  Geschäftsführer: Olaf Wagner  |    
>> Sitz: Berlin
>> Handelregister: Amtsgericht Charlottenburg HRB 77719 | USt-IdNr:  
>> DE163214194




More information about the M3devel mailing list