consider the following piece of code:
void MyClass::VideoThreadLocker::operator()(Threadable * thread) {
static_cast<BasicVideoThread *>(thread)->mutex.lock();
};
void MyClass::VideoThreadUnlocker::operator()(Threadabl e * thread) {
static_cast<BasicVideoThread *>(thread)->mutex.unlock();
};
void MyClass::processData(PipeData & data)
{
std::for_each(threads.begin(),threads.end(),VideoT hreadLocker());
cond.signalAll();
...
std::for_each(threads.begin(),threads.end(),VideoT hreadUnlocker());
}
is there a way to avoid the creation of classes VideoThreadLocker and
VideoThreadUnlocker?
I can't figure out how to use mem_fun and binders in order to achieve
the static_cast and reach mutex.lock() or mutex.unlock()
is pointers to member-functions a good alternative? Using this, I will
create one additional class (e.g.: MutexThreadOper), intead of the two
current classes
cheers
Diego Martins 3 1244
On 22 Nov 2005 09:05:10 -0800, "Diego Martins" <jo********@gmail.com>
wrote: consider the following piece of code:
void MyClass::VideoThreadLocker::operator()(Threadable * thread) { static_cast<BasicVideoThread *>(thread)->mutex.lock(); };
void MyClass::VideoThreadUnlocker::operator()(Threadabl e * thread) { static_cast<BasicVideoThread *>(thread)->mutex.unlock(); };
void MyClass::processData(PipeData & data) { std::for_each(threads.begin(),threads.end(),VideoT hreadLocker()); cond.signalAll(); ... std::for_each(threads.begin(),threads.end(),VideoT hreadUnlocker()); }
is there a way to avoid the creation of classes VideoThreadLocker and VideoThreadUnlocker?
I can't figure out how to use mem_fun and binders in order to achieve the static_cast and reach mutex.lock() or mutex.unlock()
is pointers to member-functions a good alternative? Using this, I will create one additional class (e.g.: MutexThreadOper), intead of the two current classes
cheers Diego Martins
It's very hard to say anything without seeing the declarations of
these classes. Can you post the relevant parts of the headers? Also,
how are you creating your threads? Are any of these objects in shared
libraries? Lots of variables here.
--
Bob Hairgrove No**********@Home.com
Diego Martins wrote: consider the following piece of code:
void MyClass::VideoThreadLocker::operator()(Threadable * thread) { static_cast<BasicVideoThread *>(thread)->mutex.lock(); };
void MyClass::VideoThreadUnlocker::operator()(Threadabl e * thread) { static_cast<BasicVideoThread *>(thread)->mutex.unlock(); };
void MyClass::processData(PipeData & data) { std::for_each(threads.begin(),threads.end(),VideoT hreadLocker()); cond.signalAll(); ... std::for_each(threads.begin(),threads.end(),VideoT hreadUnlocker()); }
is there a way to avoid the creation of classes VideoThreadLocker and VideoThreadUnlocker?
I can't figure out how to use mem_fun and binders in order to achieve the static_cast and reach mutex.lock() or mutex.unlock()
is pointers to member-functions a good alternative? Using this, I will create one additional class (e.g.: MutexThreadOper), intead of the two current classes
The std functions do not bind to data members. Boost's bind() (now part
of std::tr1) can bind to data members, but then there is still the
locking methods to call.
A simpler approach would be to add lock() and unlock() methods directly
to Threadable's interface and have them lock and unlock the data member
mutex themselves. In that way, std::mem_fun(&Threadable::lock) and
unlock could be used in these loops instead of the custom functor
currently in place.
Greg
hmm can this Boost binder do something like this?
void MyClass::processData(PipeData & data)
{
std::for_each(threads.begin(),threads.end(),mem_da ta(&Threadable::mutex,&Mutex::lock));
cond.signalAll();
...
std::for_each(threads.begin(),threads.end(),mem_da ta(&Threadable::mutex,&Mutex::unlock));
}
&Threadable::mutex is a pointer to member-data (which is from Mutex
class)
&Mutex::lock and &Mutex::unlock are pointers to member functions of
Mutex class
Cheers
Diego Martins This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Carlos Ribeiro |
last post by:
I thought about this problem over the weekend, after long hours of
hacking some metaclasses to allow me to express some real case data
structures as Python classes. I think that this is something...
|
by: CoolPint |
last post by:
I read in books that nested class cannot access private members of
nesting class and vice versa unless they are made friends. Somehow, my
compiler is letting my nested class member functions access...
|
by: DanielBradley |
last post by:
Hello all,
I have recently been porting code from Linux to cygwin and came across
a problem with static const class members (discussed below). I am
seeking to determine whether I am programming...
|
by: Maitre Bart |
last post by:
In test.cpp, I have a class CRunner that holds the runner's name (string)
and the runner's order (int).
To get the name, the method to use is GetName().
To get the order, the method to use is...
|
by: christopher diggins |
last post by:
// meta_binder.hpp
// The Diggins PDP (Public Domain Post) #2
// Public Domain code by Christopher Diggins, May 22, 2005
//
// Description:
// A meta-binder binds function objects to function...
| |
by: radek jedrasiak |
last post by:
Hi all,
this is about an idea for a language feature. Any feedback welcome.
To start with:
This is about a language feature, which would allow
to filter the set of available members of a...
|
by: Dave Veeneman |
last post by:
Is is legal to declare abstract members in non-abstract classes? How about
non-abstract members in abstract classes?
I am writing a base class with three derived classes. The base class will...
|
by: Genboy |
last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1,
is no longer compiling for me via the command line.
As I have done 600 times in the last year and a half, I can compile to...
|
by: Kevin Prichard |
last post by:
Hi all,
I've recently been following the object-oriented techiques discussed
here and have been testing them for use in a web application. There is
problem that I'd like to discuss with you...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |