Синхронизируется ли boost :: object_pool? - PullRequest
0 голосов
/ 02 ноября 2009

Синхронизирован ли boost :: object_pool?

Ответы [ 2 ]

4 голосов
/ 02 ноября 2009

C ++ не указывает ничего о безопасности потоков, поэтому, если это не упомянуто, то, скорее всего, не имеет дело с потоками Иногда Boost предоставляет вещи, которые могут быть поточно-ориентированными из коробки, это не один из них.

Обернуть доступ к пулу в мьютекс .

0 голосов
/ 23 декабря 2015

boost::object_pool не синхронизируется для одновременного доступа и освобождения объектов в пул и из него. но если вам нужен пул с синхронизацией, singleton_pool от boost - тот. Есть несколько ограничений на то, как начать использовать singleton_pool, но они довольно справедливы и применимы для всех приложений. Пожалуйста, смотрите примечания к загрузочной документации от здесь и здесь .

Object Usage vs. Singleton Usage

Object Usage is the method where each Pool is an object that may be created and destroyed. Destroying a Pool implicitly frees all chunks that have been allocated from it.

Singleton Usage is the method where each Pool is an object with static duration; that is, it will not be destroyed until program exit. Pool objects with Singleton Usage may be shared; thus, Singleton Usage implies thread-safety as well. System memory allocated by Pool objects with Singleton Usage may be freed through release_memory or purge_memory.

singleton_pool ограничения по использованию

Notes

The underlying pool p referenced by the static functions in singleton_pool is actually declared in a way that it is:

Thread-safe if there is only one thread running before main() begins and after main() ends -- all of the static functions of singleton_pool synchronize their access to p.
Guaranteed to be constructed before it is used -- thus, the simple static object in the synopsis above would actually be an incorrect implementation. The actual implementation to guarantee this is considerably more complicated.
Note that a different underlying pool p exists for each different set of template parameters, including implementation-specific ones.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...