Message Passing Tutorial: Difference between revisions

[unchecked revision][unchecked revision]
Line 13:
Blocking and non blocking: sender can be blocked upon send, but not necessarily. Receiver must block if there's no message waiting. Blocking means the OS will remove the process from ready queue, and won't allocate CPU resource for it until the blockade canceled. When it happens, it simply puts back the process to ready queue (most likely to the top), so next time it gains CPU, it can run. Processes on the blocked queue will not use any CPU. This saves you from [[busy loop]].
 
You should maintain a queue for every process to record blocked waiting processes. This queue must not be a circular buffer, you can implement it as a simple chained list. I assume you have written the following functions already (will be required by the tutorial):
<source lang="c">
block(processid) //function to block a process
awake(processid) //function to unblock a process
isblocked(processid) //returns true if process is blocked
pushwaitqueue(recvpid,sendpid) //put sendpid on recvpid process' sender waiting queue
topwaitqueue() //get the last pid in queue
popwaitqueue() //get the last pid in queue and remove it from queue
</source>
 
Anonymous user