Functions:
cs_lock(int mutex_id)- tries to reserve the mutex with the given ID. If the mutex is not currently owned by another process, it is assigned to the caller, and the function returns0(success). Otherwise the caller is suspended until the mutex can be assigned to it, and only then the function returns0(success).cs_unlock(int mutex_id)- releases the mutex with the given ID. If the caller is the owner of the mutex, the function returns0(success) and the server assigns the mutex to the next process in the queue. Otherwise the function returns-1and setserrnotoEPERM.
Functions:
cs_wait(int cond_var_id, int mutex_id)- suspends current process, awaiting eventcond_var_id. The calling process should be the owner of the mutexmutex_id, otherwise the function returns-1and setserrnotoEINVAL. If the calling process is the owner ofmutex_idmutex, the server releases the mutex and suspends the caller until another process callscond_var_idevent. In such case, the server enqueues process as awaiting formutex_idmutex and the function returns0once the mutex has been obtained.cs_broadcast(int cond_var_id)- broadcastscond_var_idevent. All processes awaitingcond_var_idevent are unsuspended and each of them resumes after regaining their mutex.
If the process was waiting for a mutex when it received a signal, it resumes waiting after handling it. If it was waiting for an event, it recovers the mutex and returns success (spurious wakeup).
Mutexes of terminated processes are immediately released.
The solution is designed to run in MINIX 3.2.1.
src /reflects a fragment of the MINIX source directory structure. To test, copy the contents of thesrcdirectory from the repository to the/usr/srcdirectory in MINIX. As a result, some of the original source files will be overwritten. Then install the includes, recompile and install the standard library and a new server. To enable changes to the basic system servers (PM), the system image must also be recompiled before testing. After rebooting the system, the new functionality should work after starting the server with the commandservice up /usr/sbin/cs.