Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
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.
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.
Devise an implementation of POSIX semaphores using System V semaphores.
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.