CS360 Final Exam: December 12, 2000. Question 4: Answer and Grading

Part i: If you don't use the jthreads library, you're going to have problems figuring out when to call pthread_join(). In fact, you'll have to do something just like the joining mechanism implemented in jthread.c. If you don't call pthread_join(), then whenever a client disconnects, you won't free up the stack for the thread that serviced that client. And you will run out of memory eventually.

Part ii: pthread_cond_wait() blocks the calling process and puts it on a queue associated with the condition variable. It also releases the specified lock. When it is awakened, it will have to reacquire the lack before pthread_cond_wait() can return.

pthread_cond_signal(pthread_cond_t *cv) looks at the condition variable and sees if there are any threads waiting on it. If so, then it wakes one up. If there are no waiting threads, then pthread_cond_signal() does nothing.


Grading

8 points

Part i: If you mention the correct problem, you get three points. If you don't mention the wasted use of resources (in particular, the stack space), you only got two points. If you use a relevant word, you get one point.

Part ii: 1 point for saying that wait() makes you block. 1 more point for saying that it releases the mutex. One more point if you mentioned that you have to get the mutex back before it wakes up. 1 point for saying that signal() unblocks a waiting thread. 1 point if your wording was unambiguous enough that it's clear what happens when signal() is called and there are no waiting threads.

If you didn't do any of the above, but did hint that these are synchronization actions, you got a point.