2009-11-02 40 views
0

boost :: object_pool是否同步?boost :: object_pool是否同步?

+1

请解释一下你的“同步”的意思,因为这学期没有在C的具体含义++像它在Java中,例如。 – 2009-11-02 19:59:54

+0

我的意思是线程安全 – chila 2009-11-02 20:05:46

+0

然后不,它不是 – KeatsPeeks 2009-11-02 20:09:29

回答

4

C++没有指定有关线程安全的任何内容,所以如果没有提及它,它可能不会处理线程。有时,Boost提供了可以在线程安全的东西,这不是其中之一。

mutex中包装访问池。

+0

好的谢谢你的答案 – chila 2009-11-02 20:41:14

0

boost::object_pool不同步用于同时访问和释放池中的对象。但如果你想同步池,singleton_pool从boost是一个。关于如何开始使用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.