managing threads

This is a discussion on managing threads within the C++ Programming forums, part of the General Programming Boards category; is it possible to call for a function from one thread, but run it on another?...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    98

    managing threads

    is it possible to call for a function from one thread, but run it on another?

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    either you want:
    1) to create a new thread which calls the function
    so thread 1 comes to a point where it calls begin_thread(&my_func), which creates the new thread

    2) or you want an existing thread to call the function
    then your first thread somehow has to communicate with the second thread.
    it is possible to pass a value to a thread upon creation. pass it a pointer to a queue structure, then

    thread 1 calls
    the_other_thread.get_action_queue.push(action); // push a new action into the action queue for the thread which should perform the action

    and the other thread executes something like
    Code:
    do forever {
      while(action_queue not empty)
        Action &a = action_queue.top();
        a.perform(); // perform the action
        action_queue.pop();
      }
    }
    of course it would be good getting rid of the active waiting part.
    so that the thread suspends if the queue is empty and gets waken up if something is put into the queue
    signature under construction

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    98
    i didn't understand completely what u said, but it helped me getting to the solution (which is maybe exactly what u explained).
    thanks.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    lol, sry, i explained it pretty bad i know
    still glad i could help ^^
    signature under construction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 10-17-2008, 12:28 PM
  2. Yet another n00b in pthreads ...
    By dimis in forum C++ Programming
    Replies: 14
    Last Post: 04-07-2008, 01:43 AM
  3. Classes and Threads
    By Halloko in forum Windows Programming
    Replies: 9
    Last Post: 10-23-2005, 06:27 AM
  4. problem with win32 threads
    By pdmarshall in forum C++ Programming
    Replies: 6
    Last Post: 07-29-2004, 03:39 PM
  5. Block and wake up certain threads
    By Spark in forum C Programming
    Replies: 9
    Last Post: 06-01-2002, 04:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21