how to limit access to common objects shared among multiple threads

K

K Gibbs

Lets say I have two threads which "communicate" via a shared object (passed
to them as a reference when they are created). The shared object is primarily
composed of getters and setters. In quite a few instances the two threads need
access to both types of methods. However, in some only one of the threads
should access the setter method. Eg, the control thread should be the only one
able to call the method set_LimitSwitchStautus(true); it makes no sense (nor
would it be desirable) for the GUI thread to do so. The basic structure of
the program is something like:

class Limits {
bool fLimit;
bool get_Limit() const;
void set_Limit(bool);
}

class Common {
Limits Limit;
plus a whole bunch more such contained objects
}

main {
Common blotz;
CntrlThread tCntrl(blotz);
GuiThread tGui(blotz);

tCntrl.start(); << I am using ZThreads
tGui.start();
}

where I'd like code to fail to compile (or at least do nothing) if the
GUI thread were to call set_Limit.

TIA

Ken
 
M

MiniDisc_2k2

K Gibbs said:
Lets say I have two threads which "communicate" via a shared object (passed
to them as a reference when they are created). The shared object is primarily
composed of getters and setters. In quite a few instances the two threads need
access to both types of methods. However, in some only one of the threads
should access the setter method. Eg, the control thread should be the only one
able to call the method set_LimitSwitchStautus(true); it makes no sense (nor
would it be desirable) for the GUI thread to do so. The basic structure of
the program is something like:

class Limits {
bool fLimit;
bool get_Limit() const;
void set_Limit(bool);
}

class Common {
Limits Limit;
plus a whole bunch more such contained objects
}

main {
Common blotz;
CntrlThread tCntrl(blotz);
GuiThread tGui(blotz);

tCntrl.start(); << I am using ZThreads
tGui.start();
}

where I'd like code to fail to compile (or at least do nothing) if the
GUI thread were to call set_Limit.

It does fail. set_Limit is private and cannot be accessed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top