Re: Thread-safe messages

2009-06-29 Thread Jes
I forgot to mention that we are generating C++ code in the project. Jes On 29 jun, 19:01, Jes damealpi...@hotmail.com wrote: Hi everybody, we are working on a distributed environment that uses PB, where different threads will access to the contents of messages that can be updated at any

Re: Thread-safe messages

2009-06-29 Thread Christopher Smith
I'd recommend using an atomic swap to do your updates. So you create your new version of the PB localy, and then swap it in to the memory location that is visible to all the other threads. The only real downside is you stress the heap more, and that is probably cheaper/simpler (particularly if

Re: Thread-safe messages

2009-06-29 Thread Kenton Varda
Simply adding a mutex lock in every accessor wouldn't really make them thread-safe. Consider: if (my_message.has_foo()) { DoSomething(my_message.foo()); } This is not thread-safe if my_message can be modified in a separate thread *even if* each accessor locked a mutex, because foo could