how to limit access to common objects shared among multiple threads

Discussion in 'C++' started by K Gibbs, Jul 3, 2003.

  1. K Gibbs

    K Gibbs Guest

    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
    K Gibbs, Jul 3, 2003
    #1
    1. Advertising

  2. K Gibbs

    MiniDisc_2k2 Guest

    "K Gibbs" <> wrote in message
    news:...
    > 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.


    --
    MiniDisc_2k2
    To reply, replace nospam.com with cox dot net.
    MiniDisc_2k2, Jul 3, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard
    Replies:
    11
    Views:
    770
    Jesper Nordenberg
    May 4, 2004
  2. Albretch
    Replies:
    0
    Views:
    404
    Albretch
    Dec 12, 2004
  3. MK
    Replies:
    6
    Views:
    688
    noSpAm0000
    May 16, 2005
  4. Replies:
    18
    Views:
    482
    Tim Peters
    Mar 13, 2006
  5. just_life
    Replies:
    0
    Views:
    682
    just_life
    Aug 1, 2007
Loading...

Share This Page