Your isolated processes lack efficient primitives for Inter Process Communication (IPC). One such mechanism for synchronous notification is provided by
reply, which has a clear hierarchy and therefore avoids deadlock situations with two threads sending each other at the same time.
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
sbufferwith the length
ssizesynchronously 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
int recv(void *buffer, size_t size);
blocks the current process until it receives a message. The message is stored in
bufferup to a maximum length of
sizebytes. 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.
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 – since your StuBS might have a slightly different syscall naming scheme/semantic (e.g. the first parameter of
write) you have to adapt the code accordingly:
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 (in this case
good will be appended), otherwise you have an incomplete implementation (