CS452 - Real-Time Programming - Spring 2010

Lecture 21 - Task Structure

Public Interest Announcements

  1. First train tracking assignment
  2. Workers can have code assigned by administrator

Servers and Attendant Tasks

1. Proprietor with a Notifier

2. Using a Courier

3. Using a Warehouse

4. The Secretary

5. Administrator, Worker

6. 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 );
  if ( request.type == CLIENT ) {
    parsedRequest = parse( request );
    if ( happened( parsedRequest, DB ) ) Reply( requester );
    else enqueue( parsedRequest );
  }
  else if (request.type == WORKER ) {
    updateDB ( request );
    Reply( requester );
    foreach ( queuedRequest )
      if ( happened( parsedRequest, DB ) ) {
        dequeue( parsedRequest );
        Reply( client );
      }
  }
}

FOREVER {
  Receive
  switch
  case CLIENT: Reply c't or hold
  case WORKER: Reply w'r, Reply held
}

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

Typical Time-out code

Time-out Worker

FOREVER {
    Send( detective, <timed-out>, <delay-request> )
    Delay( delay-time );
}

Detective

FOREVER {
    Receive
    switch {
    case CLIENT_TO:
        if ( to-worker available && other-worker available ) {
            Reply( to-worker );
            Reply( other-worker );
            enqueue( client );
        }
        else {
            if ( !to-worker available ) Create( to-worker ) // and initialize
            if // other-worker
    case WORKER_TO:
        if ( !first && client-waiting ) { Reply( client ); enqueue( to-client ) }
        else Reply( to-worker( delay );
        ...
    }
}

Who is the client of the detective

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

Assignments

1. Tracking & Route Finding

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: