CS452 - Real-Time Programming - Spring 2012

Lecture 23 - Administrator, Detective

Public Service Annoucements

  1. Exam: 9.00, August 8 to 11.30, August 9.
  2. I now have back my document creation tools. Assignments will start to be more uptodate.

5. Administrator, Worker

Administrator is a proprietor who does no work but only assigns work to others

Real administrators manage workers

Most workers prefer employee status to consultant status.

Worker code

  Send( administrator, nil, workOrder );
  FOREVER {
    Send( administrator, workResult, workOrder );
    workResult = doWork( workOrder );
  }

doWork might require further sends to servers or warehouses, which is harmless in this context.

Administrator code

Initialization

Administrator( ) {
  for ( i = 0; i < NUM_WORKERS; i++ ) worker[i] = Create( mypriority - 1, workerCode );
    
  FOREVER {
    Receive( requester, request );
    switch( request.type ) {
    case CLIENT:
      enqueue( orderQ, {order = {client, request}} );
      if ( !empty( employeeQ ) ) Reply( dequeue( employeeQ ) ), dequeue( orderQ ) ); 
      break;
    case WORKER:
      enqueue( employeeQ, requester);
      if ( !empty( orderQ ) ) Reply( dequeue( employeeQ ), { dequeue( orderQ ) );
      if ( request != nil ) { Reply( request.client, request.request );
      break;
    }
}

Note: Tid of the client is included in the workorder to the administrator does not have to maintain and search a list of jobs being done. (Administrators are by nature lazy!)

Alternative Worker/Administrator Model

  1. As above, Administrator includes Tid of the client in the order.
  2. Worker replies to client with result and to administrator with request for another order to process.

Comments

  1. The administrator can add a little more value.

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 even pretend to work!

Try instead, something like

FOREVER {
  Receive( *requester, request );
  switch ( request.type ) {
  case CLIENT:
    case = {requester, request.event, request.delay} );
    insert( caseDB, case );
    if ( !empty( delayQ ) && !empty( irregularQ ) ) {
      Reply( dequeue( delayQ ), case );
      Reply( dequeue( irregularQ ), case );
    }
  case DELAY:
    enqueue( delayQ, requester );
    if ( case = pending( caseDB, nil ) && !empty( irregularQ ) ) {
      Reply( dequeue( delayQ ), case );
      Reply( dequeue( irregularQ ), case );
    } 
    case = extract( caseDB, request.requester );
    if ( case != nil ) Reply( case.requester, TIME_OUT );
    break;
  case CLUE:
    enqueue( irregularQ, requester );
    if ( ( case = pending( caseDB, nil )!=nil && !empty( delayQ ) ) {
      Reply( dequeue( delayQ ), case );
      Reply( dequeue( irregularQ ), case );
    } 
    case = extract( caseDB, request.requester );
    if ( case != nil ) Reply( case.requester, EVENT );
    break;
  }
}

This is the code of a particular detective, one that notifies you which occurs first, a time-out or an event.

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: how to do them is shown above.

Who is the client of the detective

  1. Initiator of a normal action
  2. Housekeeper of the system who will clean up pathologies (Idletask?))

Return to: