CS452 - Real-Time Programming - Fall 2010

Lecture 20 - Administrator, Detective

Public Service Announcements

  1. Open house, November 9, 2010
  2. Monday notes

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

Two issues:

  1. Handles bottlenecks of all sizes.

    Define `bottleneck'.

  2. Server could be buffered on the other side

    Called a guard.

What this amounts to is

Server should be lean and hungry


4. The Secretary

Proprietor

Secretary

FOREVER {
    Receive( );
    switch ( )
    case courier && XMIT { (Reply, Reply) or enqueue }
    case courier && RCV { enqueue or (Reply, Reply) }
    case client && XMIT { (Reply, Reply) or enqueue }
    case client && RCV { enqueue or (Reply, Reply) }

Courier

FOREVER {
    Send( secretary )
    Send( prop )
}

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?))


Return to: