|
Boost : |
From: george (george13p_at_[hidden])
Date: 2006-04-02 16:25:58
hi!
class someclass
{
public:
bool a_writer(...);
bool a_reader(...);
bool another_reader(...);
....
private:
....
boost::mutex mutex;
boost::detail::atomic_count locked;
};
someclass::someclass():locked(0)
{
}
bool someclass::a_writer(.....)
{
boost::mutex::scoped_lock scoped_lock(mutex,true);
++locked;
if(something)
{
...........
--locked;
return true;
}
............
--locked;
return false;
}
bool someclass::a_reader(.....)
{
boost::mutex::scoped_lock scoped_lock(mutex,(locked!=0));
if(something)
{
.........
return true;
}
............
return false;
}
bool someclass::another_reader(.....)
{
boost::mutex::scoped_lock scoped_lock(mutex,(locked!=0));
if(something)
{
...........
return true;
}
............
return false;
}
I wanna combine atomic_count and scope locking so I can avoid locking on every
operation.
writers will get the lock,blocking all others,readers is able to go on.
the method a_writer(....) is not used very often...
I know that what I am doing is not recommended,atomic_count.hpp is for internal
use only,
but is so usefull!!
would this work as I expect?
does it worth it?
thanks!
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk