Skip to Content
PThreads Programming
book

PThreads Programming

by Dick Buttlar, Jacqueline Farrell, Bradford Nichols
September 1996
Intermediate to advanced content levelIntermediate to advanced
286 pages
7h 11m
English
O'Reilly Media, Inc.
Content preview from PThreads Programming

Chapter 3. Synchronizing Pthreads

In this chapter:

Creating threads is the easy part. It’s harder to get them to share data properly. We’re tempted to make the obvious analogy to children. To prevent damage to the Nintendo (and the children), we’ll only let the one who folds the laundry that evening play Donkey Kong. Similarly, to make threads share data safely, we must ensure that threads that would otherwise behave independently access shared data in an orderly and controlled way. This concept is called synchronization. (The other concept is called good parenting.)

Sooner or later, you’ll probably make a programming error and fail to synchronize threads. It would be nice if you could get a feel for the symptoms of synchronization failures so that you can react quickly and expertly to such a disaster. Unfortunately, as we’ll see, almost any type of quirky behavior might be regarded as a symptom of a synchronization failure. Worse, you may see problems only every so often when you run your program; at other times, if the threads in the program just happen to access data in the right order in a particular run, the program may run fine. So you may notice incorrect output at random times—perhaps in one run out of a hundred. In fact, this come-and-go quality of errors may be the best indicator that your bug is in the way in which you’ve handled thread ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming with POSIX ® Threads

Programming with POSIX ® Threads

David R. Butenhof

Publisher Resources

ISBN: 9781449364724Supplemental ContentErrata Page