CS452 - Real-Time Programming - Fall 2009

Lecture 22 - Task Structure: Detective


Servers and Attendant Tasks

1. Proprietor with a Notifier

2. Using a Courier

3. Using a Warehouse

4. Adding a Receptionist

5. Proprietor compared to Monitor

Controls a resource

Provides mutual exclusion by owning the code that accesses the resource

Proprietor provides service to clients

Like a subroutine call to the client

Proprietors versus Monitors

Monitor Proprietor Comments
access to resource localized localized Means one at a time.
service model self-service full-service Easily adapted to multi-core
service structure subroutine of client independent task Easily adapted to multi-core
priority client probably different Do we want client priority or resource priority?
address space client separate Hardware vs software protection
permissions client different Does client have permission to run certain instructions?
CPU same could be different Modern hardware works hard to support threads.

Generic Problem: Local Delay

Proprietor begins processing

Can other requests be processed? Possible strategies

  1. refusal
  2. siblings
  3. nested receive
  4. early reply

6. Administrator, Worker

7. The Detective

Simple Events

The notifier is a task that waits on events.

You could call a notifier a detective,

Complex Events

In an application there is likely to be lots of waiting on combinations of events.

We use the detective to discover that a complex event has occurred.


Code could be

  Send( part1 );
  Send( part2 );
  Send( master );


Code above doesn't work! Try instead

// InitializeDB;
// Create workers and synchronize;
// Synchronize with client;
  Receive( &requester, request );
  switch( request.type ) {
  case CLIENT:
    parsedRequest = parse( request );
    if ( happened( parsedRequest, DB ) ) Reply( requester );
    else insert( db, parsedRequest );
  case WORKER:
    updateDB ( request );
    Reply( requester );
    foreach ( queuedRequest )
      if ( happened( parsedRequest, DB ) ) { delete( parsedRequest ); Reply( client ); }

This is the code of a detective.


  1. The `code' above hides a lot of detail.
  2. We have done AND and OR.
  3. Who is likely to be a detective's client?

Return to: