|
Boost : |
From: William E. Kempf (wekempf_at_[hidden])
Date: 2003-05-08 09:26:12
Roland Richter said:
> Dear all,
>
> I'm new with Boost.Threads; I've just worked with
> Java Threads so far.
>
> One feature of the Java language is the "synchronized"
> keyword - to make variables, methods, code blocks etc.
> thread-safe. So, when I first came into the situation
> that I needed threads in C++ as well, I thought of a
> way how to reflect that feature into C++.
>
> It seems to be easy to synchronize variables - see the
> very minimalistic draft below. But what about synchronized
> class methods etc.?
Java synchronized method:
class Foo
{
public synchronized void bar() { /* code */ }
}
Boost.Threads synchronized method:
class Foo
{
public:
void bar() { boost::mutex::scoped_lock lock(m_mutex); /* code */ }
private:
boost::mutex m_mutex;
};
Java synchronized block:
class Foo
{
public void bar() {
synchronized (this) {
/* code */
}
}
}
Boost.Threads synchronized block:
class Foo
{
public:
void bar() {
{
boost::mutex::scoped_lock lock(m_mutex);
/* code */
}
}
private:
boost::mutex m_mutex;
};
> Is it worth to go further into that direction?
>
> I mean, the Boost.Thread library seems to be designed with
> safety in mind, but is still a little bit low-level.
>
> Are there any efforts to enhance the library further?
Yes.
-- William E. Kempf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk