|
Boost Users : |
Subject: Re: [Boost-users] Multithread event handling
From: Rutger ter Borg (rutger_at_[hidden])
Date: 2010-03-20 03:57:35
Matthias Vallentin wrote:
> On Fri, Jan 22, 2010 at 09:00:42PM -0600, Alessandro Bellina wrote:
>> Can somebody share their experiences on libraries or patterns used to
>> implement an event handling mechanism?
>
> Below is code for an experimental scheduler that I am currently writing,
> based on boost::asio::io_service object with a bunch of threads. I am
> also using the new boost::packaged_task and boost::shared_future classes
> that arrived with 1.41. There are a few
> issues, though:
>
> 1) I don't know why the mutex in the handler (func) does not work.
> 2) No structure (e.g., tree-like) on the tasks as in TBB, no
> priorities.
I've written something quite simple that is also able to do 2), semantics
are Asio-like,
reference_counter m_counter;
ios.post( m_counter.wrap( task1 ) );
ios.post( m_counter.wrap( task2 ) );
ios.post( m_counter.wrap( task3 ) );
m_counter.async_wait( all_complete_handler );
the reasons for me to use this are that it doesn't require additional
locking (it's using an atomic counter), and that it fits the asynchronous
model well. If there's enough interest, I can post the implementation.
Cheers,
Rutger
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net