Friedrich-Alexander-Universität Erlangen-Nürnberg  /   Technische Fakultät  /   Department Informatik
Assignment 6: Message Passing

Your isolated processes lack efficient primitives for Inter Process Communication (IPC). One such mechanism for synchronous notification is provided by send-receive-reply, which has a clear hierarchy and therefore avoids deadlock situations with two threads sending each other at the same time.

Videos (in German)

System Calls for Synchronous Inter Process Communication

You have to implement the following system calls:

  • void send(int pid, const void *sbuffer, size_t ssize, void *rbuffer, size_t rsize);
    sends the message in sbuffer with the length ssize synchronously to the process with the PID pid. This operation blocks until the recipient has received the message with recv(), processed and sent an answer using reply(). This response is stored in rbuffer, with the maximum buffer size rsize.
  • int recv(void *buffer, size_t size);
    blocks the current process until it receives a message. The message is stored in buffer up to a maximum length of size bytes. The return value contains the process identification (PID) of the sender.
  • void reply(int pid, const void *buffer, size_t size);
    sends a response message to the process identified by pid. This function should not block and only success if the target process has already performed a corresponding send() to this process and is waiting for its completion.

Test Application

You should extensively test your implementation. The fork system call can be an important assistant for this purpose.

Nevertheless, we provide an additional test case for you:

char sbuf[8194];
char rbuf[8194];
void main() {
if (fork() == 0) {
/* child */
sbuf[0] = 3;
sbuf[8192] = getppid();
sbuf[8193] = 1;
send(other, sbuf, 4097, rbuf, 4097);
char msg[] = "REPLY: AA\n";
msg[7] += rbuf[0] + sbuf[8193];
msg[8] += 4 + ppid;
write(0, msg, 10);
} else {
/* parent */
int X = recv(rbuf, 8193);
rbuf[0] = rbuf[0] + rbuf[8192];
rbuf[8193] = 7;
reply(X, rbuf, 8193);

Due to the fork() calls, this application will split into four pairs of threads. In each pair, one thread (parent) will wait for a message while the other thread (child) sends the message. The parent thread then calculates a value from the message and sends the buffer back.

On correct implementation of the system calls above, the output of this test application should be similar to:


The lines can appear in any order. The two letters following REPLY: depend on your implementation of the process identification assignment. However, on a single line those two letters must be equal!

void send(uint8_t destination, uint8_t vector)
Send an Inter-Processor Interrupt (IPI)
void exit()
Deinitialize this CPU core.
int main()
Kernels main function.