Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!decwrl!pa.dec.com!src.dec.com!Thomas Roemke From: modula-3@uni-paderborn.de (Thomas Roemke) Newsgroups: comp.lang.modula3 Subject: Re: help wanted with Thread.Alert Message-ID: <9104041502.AA04492@thor.uni-paderborn.de> Date: 4 Apr 91 15:19:47 GMT Lines: 63 To: m3 Cc: nr@dynamic.princeton.edu X-Mailer: ELM [version 2.3 PL11] nr@@Princeton.EDU (Norman Ramsey) writes: >I don't understand why my thread isn't raising Thread.Alerted in the >following program: >[..] see below. Thread.Alert(t) marks t as alerted, nothing else. No exception is raised, neither in the calling nor in the marked thread. If you want to have that behaviour, you've to raise an exception explicitly, e.g. MODULE Alert EXPORTS Main; IMPORT Rd, Wr, Thread, Fmt; FROM Stdio IMPORT stdin, stdout; PROCEDURE Copy(cl:Thread.Closure):REFANY RAISES {} = VAR result := NEW(REF INTEGER); BEGIN result^ := 0; TRY LOOP IF Thread.TestAlert() THEN EXIT; (* or RAISE Thread.Alerted *) END; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ WITH line = Rd.GetLine(stdin) DO INC(result^); Wr.PutText(stdout,Fmt.F("line is `%s\'\n",line)); END; END; EXCEPT Thread.Alerted => Wr.PutText(stdout,"Alert!\n"); | Rd.EndOfFile => Wr.PutText(stdout,"EOT\n"); END; RETURN result; END Copy; VAR t := Thread.Fork(NEW(Thread.Closure, apply := Copy)); BEGIN Thread.Alert(t); Wr.PutText(stdout,"Thread has been alerted.\n"); Wr.PutText(stdout,Fmt.F("Read %s lines\n", Fmt.Int(NARROW(Thread.Join(t),REF INTEGER)^))); END Alert. However, there's possibly a true bug left (SRC 1.6 SPARC). Using Thread.AlertJoin(t) instead of of Thread.Join(t) has to raise Thread.Alerted, since t is an alerted thread, but nothing happens..... Thomas -- (* Thomas Roemke, University of Paderborn, Germany modula-3@uni-paderborn.de ..!uunet!mcsun!unido!pbinfo!modula-3 *)