Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

53.8. Exercises

  1. Rewrite the programs in Example 48-2 and Example 48-3 (Section 48.4) as a threaded application, with the two threads passing data to each other via a global buffer, and using POSIX semaphores for synchronization.

  2. Modify the program in Example 53-3 (psem_wait.c) to use sem_timedwait() instead of sem_wait(). The program should take an additional command-line argument that specifies a (relative) number of seconds to be used as the timeout for the sem_timedwait() call.

  3. Devise an implementation of POSIX semaphores using System V semaphores.

  4. In Section 53.5, we noted that POSIX semaphores perform much better than System V semaphores in the case where the semaphore is uncontended. Write two programs (one for each semaphore type) to verify this. Each program should simply increment and decrement a semaphore a specified number of times. Compare the times required for the two programs.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial