Thetasksinthislayerperformhigh-levelI/Ooper-ationsthat transferdata synchronouslytomessagequeues in the Queueing layer. Unlike the Asyn-chronous layer, tasks inthe Synchronouslayer are
 that have their own run-timestack and registers. Therefore, they can block while performing synchronous I/O.
This layer provides a synchronization and buffer-ing point between the Synchronous task layer andtheAsynchronoustasklayer. I/Oeventsprocessedby asynchronous tasks are buffered in messagequeues at the Queueing layer for subsequent re-trieval by synchronous tasks (and vice versa).
Asynchronous task layer
BSD UNIX kernel
The tasks in this layer handle lower-level eventsfrom multipleexternal event sources (such as net-work interfaces or terminals). Unlike the Syn-chronous layer, tasks in the Asynchronous layerare
that do not have their ownrun-time stack or registers. Thus, they cannot block indeﬁnitely on any single source of events.
External event sources
External devices (such as network interfaces anddisk controllers) generate events that are receivedand processed by the Asynchronous task layer.
Figure 3 illustratesthe dynamic collaborationamong partici-pantsintheHalf-Sync/Half-Asyncpatternwheninputeventsarrive at an external event source (output event processing issimilar). These collaborations are divided intothe followingthree phases:
– in this phase external sources of eventsinteract with the Asynchronoustask layer via interruptsor asynchronous event notiﬁcations.
– in this phase the Queueing layer pro-vides a well-deﬁned synchronization point that buffersmessages passed between the Synchronous and Asyn-chronous task layers in response to input events.
– in this phase tasks in the Synchronouslayer retrieve messages placed into the Queueing layerby tasks in the Asynchronous layer. Note that the pro-tocol used to determine how data is passed between theSynchronous and Asynchronous task layers is orthogo-nal tohowthe Queueinglayer mediates communicationbetween the two layers.The Asynchronous and Synchronous layers in Figure 3communicate in a “producer/consumer” manner by passing
EXTERNAL EVENTEXTERNAL EVENTPROCESS MSGPROCESS MSG
EXECUTE TASK EXECUTE TASK ENQUEUE MSGENQUEUE MSG
ExternalExternalEvent SourceEvent SourceAsyncAsyncTask Task SyncSyncTask Task MessageMessageQueueQueue
DEQUEUE MSGDEQUEUE MSG
A S Y N C A S Y N C P H A S E P H A S E Q U E U E I N G Q U E U E I N G P H A S E P H A S E S Y N C S Y N C P H A S E P H A S E
RECV MSGRECV MSG
Figure 3: Collaboration between Layers in the Half-Sync/Half-Async Patternmessages. The key to understanding the pattern is to recog-nize that Synchronous tasks are active objects. Thus, theycan make blocking
calls at any point inaccordance with their protocol. If the data is not yet avail-able tasks implemented as active objects can sleep until thedata arrives. In contrast, tasks in the Asynchronous layerare passive objects. Thus, they cannot block on
calls.Instead, tasks implemented as passive objects are triggeredbynotiﬁcationsorinterruptsfromexternal sources of events.
The Half-Sync/Half-Async pattern yields the followingben-eﬁts:
Higher-level tasks are simpliﬁed
because they areshielded from lower-level asynchronous I/O. Complexconcurrency control, interrupt handling, and timing is-sues are delegated to the Asynchronoustask layer. Thislayer handles the low-level details (such as interrupthandling) of programming an asynchronous I/O sys-tem. The Asynchronouslayer alsomanages theinterac-tionwithhardware-speciﬁc components(such as DMA,memory management, and device registers).
Synchronization policies in each layer are decoupled.
Therefore each layerneed notuse thesame concurrencycontrol strategies. For example, in the single-threadedBSD UNIX kernel the Asynchronous task layer imple-ments concurrency control via low-level mechanisms(such as raising and lowering CPU interrupt levels). Incontrast, user processes in the Synchronous task layerimplement concurrency control via higher-level syn-chronization constructs (such as semaphores, messagequeues, conditionvariables, and record locks).
Inter-layer communicationis localized at a single point
because all interaction is mediated by the Queueinglayer. The Queueing layer buffers messages passed3