2009-11-02 5 views
0

boost :: object_pool est-il synchronisé?boost :: object_pool est-il synchronisé?

+1

S'il vous plaît expliquer ce que vous entendez par « synchronisée » que ce terme n'a pas de signification particulière en C++ comme il ne en Java, par exemple. –

+0

Je veux dire – chila

+0

thread-safe alors non, ce n'est pas – KeatsPeeks

Répondre

4

C++ ne précise rien au sujet de la sécurité des threads, donc si elle ne figure pas il ne risque pas d'un filetage traite. Parfois, Boost fournit des choses qui peuvent être thread-safe hors de la boîte, ce n'est pas l'un d'entre eux.

accès Wrap à la piscine dans un mutex.

+0

ok merci pour la réponse – chila

0

boost::object_pool n'est pas synchronisé pour l'accès simultané et libération des objets et de la piscine. mais si vous voulez un pool avec synchronisation, singleton_pool de boost est celui. Il y a quelques restrictions sur la façon de commencer à utiliser singleton_pool, mais ils sont assez justes et applicables pour toutes les applications. S'il vous plaît voir ci-dessous des notes de la documentation de démarrage de here et here.

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. 

restrictions usages 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. 
Questions connexes