Accessing a thread's object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ryan

    #1

    Accessing a thread's object

    I'm using boost::threads and trying to access the members of the
    functor that I start the thread on and can't find information on how to
    do it anywhere.

    It took me a while to even figure out what was going on but eventually
    I determined that creating a new thread actually just COPIES your
    functor object. Therefore changing the object's member values from
    within the thread has NO effect whatsoever on the object you used to
    initiate the thread.

    Basically what I'm doing is I create object A. Object A has the ()
    operator that boost threads automatically start runnning.

    I tell boost I want to start A on it's own thread.

    A does some stuff (in this case 'A' is a thread dedicated to serving a
    client and my program creates a new A for every client that connects so
    that it can cater to everyone at once).

    The problem is, if I then call A.getWhatever() it returns null because
    everything that has been changed, to my absolute delight, has been
    changed on the boost::thread's copy of A and completely ignored the one
    I passed into the thread() function.

    Basically all I want to know is if there is any way to just access the
    thread's local copy of the object. If not it looks like my only other
    option is to pass in a pointer to another object that will hold all of
    the state data which will mean rewriting a HUGE amount of code :(

    Let me know if I've left anything out. I can barely comprehend most of
    the stuff I'm doing in this program myself lol.

  • Victor Bazarov

    #2
    Re: Accessing a thread's object

    Ryan wrote:
    I'm using boost::threads and trying to access the members of the
    functor that I start the thread on and can't find information on how
    to do it anywhere.
    >
    [..]
    You probably want to pass the address of the thread object to the
    function you're using as the thread function. Unfortunately, boost
    libraries are not really on topic here. Besides, don't they have
    their own online forums?

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask


    Comment

    Working...