|
Boost Users : |
Subject: Re: [Boost-users] [thread] "almost works" clarification
From: Bjorn Reese (breese_at_[hidden])
Date: 2013-05-26 06:01:01
On 05/25/2013 02:34 PM, Gaetano Mendola wrote:
> Instead of a solution (bugged) please explain what you are not able
> to achieve with the current boost thread.
I cannot speak on behalf of the original poster, but I have seen this
complaint before, so I will take a stab at it.
The basic complaint is that boost::thread abstraction is too low-level
for certain common use cases. This is not necessarily a complaint about
boost::thread itself.
Keep in mind that the average application programmer is not intimately
familiar with threading, and will prefer any solution that allows him
to focus on the application logic rather than on threading mechanisms.
In the most common use case that I have encountered, people are looking
for two improvements. First, a recognizable entry-point (the
MyWorker::run() in the blog example.) Second, a polite way to notify
the thread that it should shut down (the MyWorker::stop() in the blog
example.)
The first improvement is not important, so I will disregard it here.
The typical solutions to the second improvement are to use condition
variables, interruption-points, or message passing.
Condition variables are doable, but you can easily introduce threading
errors in your application code (as the blog example demonstrates.)
With interruption-points you have to catch the exceptions to handle the
shut down. In some cases this can result in complex application code.
Furthermore, the application programmer has to make sure that his code
executes some interruption point.
Message passing is nice, but only if you already are using a thread-safe
message queue. Otherwise, it is a bit of an overkill solution to shut
down a thread.
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