Thread: How to pass data between 2 Threads

  1. #1
    Registered User
    Join Date
    May 2002

    Question How to pass data between 2 Threads

    Hi All,

    My program has 2 threads, a MainThread and a ChildThread. Each thread has its own queue .
    Every time the ChildThread receives data, it put in its queue and send that data to MainThread and MainThread keep track that data in its own queue also.
    void *Main_Thread(void)
        Queue mainQueue;
        // wait to receive data from Child Thread
    void * Child_Thread(void)
       Queue childQueue;
       // wait for data arrive and put in the queue
      //  send the data to Main Thread to put in its queue
    Does anyone know how to pass data between Threads?

    Thank you very much for your help.
    Last edited by dv007; 02-21-2006 at 05:16 PM.

  2. #2
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Use a shared memory resource.

    Don't forget to access them via protected methods. e.g. InterlockedXxx in Windows.
    Open source isn't a matter of life or death......
    .......its much more important than that!!

    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  3. #3
    Registered User
    Join Date
    Sep 2004
    Question, from the look of it I want to guess your using pthreads. If that is the case, then you use a global queue, which both threads will be able to access. If you this though, in order to keep one thread from accessing it while the other one is, look into mutexs
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. data structure design for data aggregation
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-20-2008, 06:43 AM
  4. All u wanted to know about data types&more
    By SAMSAM in forum Windows Programming
    Replies: 6
    Last Post: 03-11-2003, 03:22 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM