CS452 - Real-Time Programming - Fall 2010

Lecture 21 - Detective, Projects

Public Service Announcements

  1. Open house, November 9, 2010

Task Structure

Servers and Attendant Tasks

1. Proprietor with a Notifier

2. Using a Courier to Improve Receive

3. Using a Warehouse to Improve Transmit

4. The Secretary

5. Administrator, Worker



Generalization of proprietor

Administrator maintains an array of records

Administrator works as he can on any one of the tasks.

Real administrators manage workers

Worker code

  Receive( &bossTid, <initData> );
  Reply( bossTid, ... );
  FOREVER {
    Send( administrator, workResult, order );
    doWork( workOrder );
  }

Administrator code

Administrator( ) {
  Initialize( ); // orderQ, workerQ
  for ( i = 0; i < NUM_WORKERS; i++ ) worker[i] = Create( workerCode );
  for ( i = 0; i < NUM_WORKERS; i++ ) {
    Send( worker[i], initData , ... );
    enqueue( workerQ, worker[i] );
  }
  // RegisterAs
  FOREVER {
    error = Receive( requester, request );
    switch( request.type ) {
    case CLIENT: // enqueue w/o or Reply w/o
      enqueue( orderQ, workOrder = {requester, request}; {
      if( !empty( workerQ ) && available( <resources> ) )
         Reply( dequeue( workerQ ), { dequeue( orderQ ), <resources> );
      break;
    case WORKER: // Reply result, enqueue w'r or Reply w/o
      Reply( request.client, request.result );
      enqueue( workerQ, requester );
      if( !empty( orderQ ) && available( <resources> ))
        Reply( dequeue( workerQ ), { dequeue( orderQ ), <resources> } );
      break;
    }
  }
}

Alternative Administrator Code

Administrator( ) {
  Initialize( );
  for ( i = 0; i < NUM_WORKERS; i++ ) worker[i] = Create( workerCode );
  for ( i = 0; i < NUM_WORKERS; i++ ) Send( worker[i], ... , ... );
    // Initialize orderQueue, workerQueue
    // RegisterAs
  FOREVER {
    error = Receive( requester, request );
    switch( request.type ) {
    case CLIENT:
       enqueue ( workfifo, workorder );
       while ( !empty( workfifo ) )
          if ( complete ( workorder, data ) && workerTid = next( workerQ ) ) { 
             Reply( client, workerTid, ... );
             Reply( worker, workorder );
          }
       break;
    case WORKER:
      if( ( workOrder = deQueue( orderQueue) ) ) {
        workOrder = {workOrder.client, workOrder.request};
        Reply( requester, workOrder );
      } else enqueue( workerQueue, requester );
    }
  }
}

8. 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.

Conjunction

Code could be

FOREVER {
  Send( part1 );
  Send( part2 );
  ...
  Send( master );
}

Disjunction

Code above doesn't work! Try instead

// InitializeDB;
// Create workers and synchronize;
// Synchronize with client;
FOREVER {
  Receive( *requester, request );
  switch ( reqest.type )
  case CLIENT:
    insert( reqQ, request );
    if ( happened( DB, request ) ) Reply( dequeue( reqQ ), ... );
    break;
  case WORKER:
    update ( DB, request );
    // Reply or enquqe requester
    foreach request in reqQ
      if ( happened( DB, request ) ) Reply( extract( reqQ ), ... );
    break;
}

This is the code of a detective.

Not

We can say that an event has not happened yet.

Only at the end of the universe can we say that an event simply has not happened.

Time-outs are needed for NOT

Who is the client of the detective

  1. Initiator of a normal action

Housekeeper of the system who will clean up pathologies (Idletask?))


Assignments

1. Tracking

What you are expected to do

2. Avoiding

What you are expected to do


Projects

1. Train style

Give trains roles and objectives. For example,

Another example,

2. Game style

The track is a graph.

Many games are played on graphs

E.g. watchmen and bandit.


Return to: