next up previous
Next: Memory management Up: Solution description Previous: Tasks and threads

Messaging system

The kernel provides an asynchronous inter-task messaging system through the send_msg, get_msg and get_msg_count system calls. The messages have a fixed size defined by the implementation, and the kernel guarantees that messages arrive in FIFO order, but each message queue has a maximum capacity which is also implementation-defined. When a message is sent using the function int send_msg(int to_address, int port, void *msg), the contents of the message pointed by msg are copied to the queue corresponding to port number port of task to_address. The reception of messages is done in an analogous fashion using the function int get_msg(int port, void *msg, int *id), which removes the fist message in the supplied port's queue and copies it's contents to the address msg. The variable id is used to return the id of the sender task. Both functions return 0 on success. The function int get_msg_count(int port) returns the amount of messages in the queue of the supplied port. Before a port can be used to receive messages, it must be opened using the open_port system call, setting it's protection mode (it works in an analogous fashion to thread's protection modes) and the numerically higher privilege level that can send messages to this port. When a port is closed using the close_port system call, the associated message queue is flushed and the port becomes unavailable (attempts to send messages to a closed port will fail).


next up previous
Next: Memory management Up: Solution description Previous: Tasks and threads
2002-09-17