boost :: object_pool是同步的吗?

时间:2009-11-02 19:49:52

标签: c++ boost

boost :: object_pool是否已同步?

2 个答案:

答案 0 :(得分:4)

C ++没有指定任何关于线程安全性的东西,所以如果没有提到它,它可能不会处理线程。有时,Boost会提供开箱即用的线程安全的东西,但这不是其中之一。

mutex

中包含对池的访问权限

答案 1 :(得分:0)

对于并发访问和从池中释放对象,

boost::object_pool未同步。但如果你想要同步池,那么来自boost的singleton_pool就是那个。关于如何开始使用singleton_pool的限制很少,但它们非常公平,适用于所有应用程序。请参阅以下herehere启动文档中的说明。

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.
相关问题