are boost::interprocess containers thread-safe?

Hi, I must implement a multiple producer-consumer IPC application in win32 (but will port to linux in near future). I am wondering whether the boost::interprocess container like list, vector or map is thread-safe (actually, interprocess-safe?) or I need to use lock in my producer-consumer application? I mean, can Producer just simply put shared memory string to container and take it from Consumer without any lock? Or is there any multiple producer-consumer example that uses boost::interprocess? Thanks a lot. -- View this message in context: http://old.nabble.com/are-boost%3A%3Ainterprocess-containers-thread-safe--tp... Sent from the Boost - Users mailing list archive at Nabble.com.

El 17/12/2009 14:44, blp330 escribió:
Hi,
I must implement a multiple producer-consumer IPC application in win32 (but will port to linux in near future). I am wondering whether the boost::interprocess container like list, vector or map is thread-safe (actually, interprocess-safe?) or I need to use lock in my producer-consumer application?
They offer the same guarantees as standard containers: it's safe to read a container from two threads. It's unsafe to read and write it at the same time. You'll need to use locks/condition variables for that, just like you'll need to do for containers shared between threads of the same process. Best, Ion

OK, thank you. :) I am curious about: 1. Does any lock-free containers for boost::interprocess (just like boost::lockfree)? 2. Mutex and any other sync objects does not use native win32 API to implement. (It uses file to emulate that, right?) Does any performance impact in win32 platform to use locks? Does anything I should notice to use boost::interprocess in win32 platform? 3. I should use lock for containers to implement multiple producer consumer, or just simply use message_queue for that? any good suggestion or recommend? Thank you very much. -- View this message in context: http://old.nabble.com/are-boost%3A%3Ainterprocess-containers-thread-safe--tp... Sent from the Boost - Users mailing list archive at Nabble.com.

El 17/12/2009 15:17, blp330 escribió:
OK, thank you. :)
I am curious about:
1. Does any lock-free containers for boost::interprocess (just like boost::lockfree)?
No.
2. Mutex and any other sync objects does not use native win32 API to implement. (It uses file to emulate that, right?)
Process-shared mutexes and condition variables and emulated using atomic operations and waits.
Does any performance impact in win32 platform to use locks?
If there is low contention, no. For high contention programs, spin-and-lock strategies can have a big performance impact.
Does anything I should notice to use boost::interprocess in win32 platform?
3. I should use lock for containers to implement multiple producer consumer, or just simply use message_queue for that? any good suggestion or recommend?
It depends on what you need (ordered that by a key, reallocation needs, etc.) Think about it just like you will think for inter-thread communications. best, Ion
participants (2)
-
blp330
-
Ion Gaztañaga