Книга: Programming with POSIX® Threads

7.1 Extended synchronization

Mutexes and condition variables are flexible and efficient synchronization. tools. You can build just about any form of synchronization you need using those two things. But you shouldn't build them from scratch every time you need them. It is nice to start with a general, modular implementation that doesn't need to be debugged every time. This section shows some common and useful tools that you won't have to redesign every time you write an application that needs them.

First we'll build a barrier. The function of a barrier is about what you might guess — it stops threads. A barrier is initialized to stop a certain number of threads — when the required number of threads have reached the barrier, all are allowed to continue.

Then we'll build something called a read/write lock. A read/write lock allows multiple threads to read data simultaneously, but prevents any thread from modifying data that is being read or modified by another thread.

Оглавление книги

Оглавление статьи/книги

Генерация: 1.491. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз