Question: Consider the following multi - threaded C pseudocode: 1 . void * getMsg ( ) { 2 . lock ( &mutex ) ; 3 .

Consider the following multi-threaded C pseudocode:
1. void* getMsg(){
2. lock(&mutex);
3. sem_wait(&sem);
4. void* msg = popQueue(&queue);
5. unlock(&mutex);
6. return msg;
7.}
8. void addMsg(void* msg){
9. lock(&mutex);
10. pushQueue(&queue, msg);
11. unlock(&mutex);
12. sem_post(&sem);
13.}
How can you fix the bug(s) in this code? Select all of the changes that must be applied to make this
code work.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!