[M3devel] User-level threading

Mika Nystrom mika at async.caltech.edu
Mon Jul 16 06:50:52 CEST 2007


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