[M3devel] User-level threading
Tony Hosking
hosking at cs.purdue.edu
Mon Jul 16 18:47:06 CEST 2007
This runs fine for me on Darwin pthreads up until it fails trying to
create a new pthread after 6982 threads: the call to pthread_create
returns an error code. I am assuming the error is due to hitting
some system limit.
On Jul 16, 2007, at 12:50 AM, Mika Nystrom wrote:
> 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.
More information about the M3devel
mailing list