-
November 9th, 2009, 02:58 PM
#1
howto restric a method to being absolutely constant
Hi,
I want to be able to declare a restriction in C++ so that a functor object can not change it's state or the state of any object it has a reference to upon calling the functor. This would have to be something like an "absolute const" object. At the same time I would like to be able to pass arguments upon calling the function object who's state it can change.
I need this because these functor objects will be scheduled between threads and I want to make sure that executing them only affects objects from the targeted thread, passed as arguments. This way I can guarantee no concurrency issues will occur.
something like this:
Code:
//instances on thread 1
class TargetedFunctor
{
public:
TargetedFunctor(...);
virtual void operator(Target &target) absolute_const;
};
// At some point thread 1 calls
x.scheduleFunctor(f, 42);
//instances on thread 2
class Queue{
public:
// threadsafe method
void scheduleFunctor(absolute_const TargetedFuntor &f, Time when){
...
}
};
//At time "when" thread 2 calls
f(target);
I fear that C++ supports no such restrictions. If so, does anyone know any C++ extensions or any other languages that do?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|