| Names | constant across applications & executions | interface | Associated with a set of services (an API) |
| Task Ids | vary across applications & executions | implementation | Associated with a particular set of instructions and data (an execution) |
int RegisterAs( char *name );
\0 terminated.int WhoIs( char *name );
\0 terminated.Unregister primitive?typedef struct {
int type;
char *name;
} NSstruct;
int RegisterAs( char *name ) {
int result;
NSstruct req;
req.type = REGISTERAS;
req.name = name;
bytes = Send( NSTid, &req, sizeof(NSstruct), (char *) result, sizeof(int) );
if ( bytes != sizeof(int) ) {
// Do something error-like
} else return result;
}
There are lots of possible variations, and this one is by no means the best.
typedef struct {
int type;
char *name;
} NSstruct;
int bytes, tid;
NSstruct req;
// initialize tables
FOREVER {
bytes = Receive( &tid, &req, sizeof(NSstruct) );
if ( bytes != sizeof(NSstruct) ) {
// Reply with error
} else {
switch( req.type ) {
case REGISTERAS:
insert( name, tid );
Reply( tid, SUCCESS, sizeof(int) );
break;
case WHOIS:
result = lookup( name );
Reply( tid, result, sizeof(int) );
break;
default
Reply( tid, ERROR, sizeof(int) );
break;
}
}
}
Return to: