[Oberon] Re: Oberon Digest, Vol 36, Issue 5

Thomas Frey thomas.frey at alumni.ethz.ch
Mon Sep 18 18:20:07 CEST 2006


> What is wrong with using threads in the following way in Bluebottle Oberon?
> *****************************************************

The AWAIT statement must be in an exclusive block. Also all state
variables used in any of the await statements may only be changed in
exclusive blocks (The later is not checked by the compiler or the
runtime but is required for correctness)

E.g.

BEGIN {EXCLUSIVE}
  ...
  AWAIT(something)
  ...
END
...
BEGIN {EXCLUSIVE}
  ...
  something := FALSE
  ...
END

but nowhere in the code "something" may be used outside of an
exclusive block, otherwise the behaviour of the threads is not
guaranteed.

the same goes for complex conditions like
BEGIN {EXCLUSIVE}
  ...
  AWAIT(this OR that)
  ...
END
...
BEGIN {EXCLUSIVE}
  ...
  this:= FALSE
  ...
END

neither "this" not "that" may ever be used outside of an exclusive
block in the entire program (initialization in the module body or the
constructor of the active object are ok without exclusive in some
conditions when you know exactly what you are doing)

If there are more questions about the topic, i can reply later in more
details (e.g. weekend)

--Thomas


> MODULE threads;
>
> TYPE workthread=OBJECT
>
> BEGIN{ACTIVE, normal priority}
> REPEAT
>     AWAIT(gothreads);
>     work;
>     INC(threadsdone);
>     AWAIT(~gothreads);
> END;
>
> VAR
>    threadsdone:INTEGER;
>    gothreads:BOOLEAN
> (*main thread*)
>
> PROCEDURE go*;
> BEGIN
>      gothreads:=TRUE;
>      AWAIT(threadsdone=n); (* for n threads*)
>      gothreads:=FALSE
> END go;
>
> BEGIN
>      create n thread objects
> END threads;
>
> each time "go" is called every thread does its work once before "go"
> returns to the caller. why does this create traps in the kernel log
> that trace to the AWAIT statement?
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>


More information about the Oberon mailing list