6.2 Concurrent objects

In this section, we describe how to define concurrent objects and associated schedulers.

A simple coroutine, as described in the previous sections retains control until it voluntarily gives up control by executing a suspend.

In this section, we introduce the notion of pre-emptive suspend – implying that execution of a coroutine may be pre-empted after a specific number of time units.

The statement R.attach(50) resumes execution of the coroutine R – and after 50 units of time, R is suspended. A subsequent R.attach(50) will resume execution of R at the point of suspension.

SimpleSystem: obj
   Process:
      ...
      this(Process).suspend
      inner(Process)
      ...
   P1: obj Process
       ...
   P2: obj Process
       ...
   P3: obj Process
       ...
   cycle
       P1.attach(50)
       P2.attach(60)
       P3.attach(70)
 

The SimpleSystem object contains a Process pattern and three objects, P1P2, and P3, subpatterned from Process.

The SimpleSystem alternates between executing the three Process objects and gives P1P2 and P3, 50, 60 or 70 units of execution time respectively.

The SimpleSystem object is thus a simple scheduler for the three Process objects.

By using the above primitives/principles, it is possible to build concurrency abstractions implementing monitor-like systems, rendezvous-like systems (in the style of Ada and CSP), message-passing systems, Actor-like systems, etc. See the reference mentioned here for examples of this.

Hello world