Thread Interruption Best Practice
Hi List, I'm fairly new to boost, and have recently started to use the threading system from v1.46 in an app I'm writing targeting Linux. This was primarily to enable execution of threads to be blocked until a condition variable is set, at which point the thread is kicked awake and actions whatever is waiting to be done. All good, and all working as expected. However, I've got another thread which sits listening for data on a socket using a Linux select() call. This blocks until data is available for reading, at which point it is read from the socket as expected. This also works fine, except on termination of the application. Using native Linux implementations, a signal can be sent to the thread that is blocking on the select() call, at which point the call returns, and the EINTR error is set. I can therefore check for this condition and handle appropriately. Is there a way to send a Linux signal (or boost equivalent) to a specific boost thread to emulate this behaviour? Failing that, is there an alternative implementation of the classic Linux select()/read() functionality using boost classes? I had a look at the async I/O library and it seems a bit convoluted. TIA, Dom
On 03/20/2011 02:45 PM, Dom Driver wrote:
Failing that, is there an alternative implementation of the classic Linux select()/read() functionality using boost classes? I had a look at the async I/O library and it seems a bit convoluted.
TIA,
Dom
Hi Dom - This is the type of thing that ASIO does well. What type of problems are you having with the library? Understanding the proactor model is critical to understanding ASIO. The "overview" portion of the docs in ASIO will give you a good grasp of how to approach problems with a proactor. You may also find my BoostCon'10 talk of ASIO beneficial: video: http://boostcon.blip.tv/file/4171562/ slides: http://www.objectmodelingdesigns.com/boostcon10/ HTH - michael -- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com
Hi, if I understand your problem you want the thread blocking in select to return? If yes you could add add pipe to select for reading which will wake you up from select and indicate you that you have to terminate. Oliver -------- Original-Nachricht --------
Datum: Mon, 21 Mar 2011 10:45:46 +1300 Von: Dom Driver
An: boost-users@lists.boost.org Betreff: [Boost-users] Thread Interruption Best Practice
Hi List,
I'm fairly new to boost, and have recently started to use the threading system from v1.46 in an app I'm writing targeting Linux. This was primarily to enable execution of threads to be blocked until a condition variable is set, at which point the thread is kicked awake and actions whatever is waiting to be done.
All good, and all working as expected.
However, I've got another thread which sits listening for data on a socket using a Linux select() call. This blocks until data is available for reading, at which point it is read from the socket as expected. This also works fine, except on termination of the application.
Using native Linux implementations, a signal can be sent to the thread that is blocking on the select() call, at which point the call returns, and the EINTR error is set. I can therefore check for this condition and handle appropriately.
Is there a way to send a Linux signal (or boost equivalent) to a specific boost thread to emulate this behaviour?
Failing that, is there an alternative implementation of the classic Linux select()/read() functionality using boost classes? I had a look at the async I/O library and it seems a bit convoluted.
TIA,
Dom
-- GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit gratis Handy-Flat! http://portal.gmx.net/de/go/dsl
participants (3)
-
Dom Driver
-
Michael Caisse
-
Oliver Kowalke