2009-11-02 35 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.