Simplest threaded example
Marc Lehmann
schmorp at schmorp.de
Fri Jul 30 04:03:06 CEST 2010
On Thu, Jul 29, 2010 at 11:28:46AM +0900, Horacio Sanson <hsanson at gmail.com> wrote:
> After reading several times the documentation/mailing list this is the simplest
> threading model I found to work with libev (C++):
Really? simplest?
> ev::io m_stdinWatcher;
> ev::sig m_sigintWatcher;
> ev::sig m_sigtermWatcher;
you really need sig watchers in the simplest case?
> void print() {
> boost::mutex::scoped_lock lock(m_coutMutex);
this also seems to muddle the issue.
anyway, it seems you run the same loop in multiple threads, with a lock
- thats "correct", but since you haven't explained what you wanted to
achieve, it's not clear whether this is actually what you want.
> The question would be: is this an acceptable threading model for libev and my
> application?
for libev yes, for your app, no clue :)
> Is this a correct way of doing threading with libev?? because helgrind complains
> a lot about possible race conditions with this code but I think is due to boost
> and not libev.
If I understand your example, yes, it should be ok - you seem to never
call a function with the same loop argument in parallel.
However, since your (example) program doesn't really do anything, it's hard
to tell whether this achives your goal - for that, you'd have to explain how
you want to use this.
It is a valid threading model (simply because there is no "threading"
w.r.t. libev). It might achieve what you want (some kind of
leader/follower pattern), and might be the right choice. You can also
structure things differently (and more complex).
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / schmorp at schmorp.de
-=====/_/_//_/\_,_/ /_/\_\
More information about the libev
mailing list