Exercises

team bbl


11.1

Modify the example shown in Figure 11.4 to pass the structure between the threads properly.

11.2

In the example shown in Figure 11.13, what additional synchronization (if any) is necessary to allow the master thread to change the thread ID associated with a pending job? How would this affect the job_remove function?

11.3

Apply the techniques shown in Figure 11.14 to the worker thread example (Figure 11.1 and Figure 11.13) to implement the worker thread function. Don't forget to update the queue_init function to initialize the condition variable and change the the job_insert and job_append functions to signal the worker threads. What difficulties arise?

11.4

Which sequence of steps is correct?

  1. Lock a mutex (pthread_mutex_lock).

  2. Change the condition protected by the mutex.

  3. Signal threads waiting on the condition (pthread_cond_broadcast).

  4. Unlock the mutex (pthread_mutex_unlock).

or

  1. Lock a mutex (pthread_mutex_lock).

  2. Change the condition protected by the mutex.

  3. Unlock the mutex (pthread_mutex_unlock).

  4. Signal threads waiting on the condition (pthread_cond_broadcast).

    team bbl



    Advanced Programming in the UNIX Environment
    Advanced Programming in the UNIX Environment, Second Edition (Addison-Wesley Professional Computing Series)
    ISBN: 0321525949
    EAN: 2147483647
    Year: 2005
    Pages: 370

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net