Re: Thread-safe messages

2009-07-01 Thread Jes
Thanks Cristopher and Kenton! I will provide a Mutex to the higher levels as you recommend. Jes. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to protob

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

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 you

Thread-safe messages

2009-06-29 Thread Jes
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 moment through the network. I wonder if there is an easy way to transform the (derived) Messages into a thread-safe version. Maybe th

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 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 moment through the ne