-- Example of Ada-style tasking in LX -- Consumer and producer tasks with synchro buffer import ASCII = LX.ASCII import TASK = LX.TASKING -- Make all references to 'TASK' implicit using TASK -- Buffer object used for synchronization {protected} record Buffer with {entry} function Count() return unsigned {entry} function Available() return unsigned when Count() > 0: {entry} procedure Read(out character C) when Available() > 0: {entry} procedure Write(in character C) -- Producing task task Producer is with character C loop -- ... produce the next character Buffer.Write C exit if C = ASCII.EOT -- Consuming task task Consumer is with character C loop Buffer.Read C exit if C = ASCII.EOT -- ... consume the character -- Implementation of Buffer (possibly a separate file) {protected} record Buffer body is with array Pool[1..100] of character unsigned Count := 0 unsigned In_Index := 1, Out_Index := 1 {entry} function Count() return unsigned is return Count {entry} function Available() return unsigned is return Size(Pool)-Count {entry} procedure Read(in character C) is Pool[In_Index] := C In_Index := (In_Index mod Size(Pool)) + 1 Count += 1 {entry} procedure Write(out character C) is C := Pool[Out_Index] Out_Index := (Out_Index mod Size(Pool)) + 1 Count -= 1