Thread: returning value from one threaded function to other threaded function

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    8

    returning value from one threaded function to other threaded function

    Hello Guys,

    I am using two threads and i want to take value of a function from one thread and use it in other.

    I am not good at the concepts of threads.

    Here is the following code:

    Code:
    void ThreadA(void const *argument)
    {          
        uint32_t status = I2S002_FAIL;
    
        status = I2S002_Config(&I2S002_Handle0, &I2SConfig_U0C1_A);
        if (status != DAVEApp_SUCCESS)
        {
            while (1);
        }
    
        while (1) {
            status = I2S002_RegisterTxPPBuf(&I2S002_Handle0, (uint32_t*) TXBuf,PLen);
            }
    ....
    ....
    }
    
    void ThreadB(void const *argument)
     {
     FILE *ptr;
     uint16_t result, block_size;
     uint16_t num_blocks;
     status_t status1 ;
     status_t Status ;
     block_size = sizeof(temp_buffer);
     num_blocks = sizeof(char);
     Status =  mount(0, &myfsObject);
     if(Status != DAVEApp_SUCCESS)
     {
     while(1);
     }
     ptr = fopen("test.raw", "r+");
     fseek(ptr, 0, SEEK_SET);
     result = fread(&temp_buffer, num_blocks, block_size, ptr);
     if(result == 0)
     {
         while(1);
     }
    
     status1 = fclose(ptr);
    return;
    }
    
    int main(void)
    
    {...
    ...
     ThreadId = osThreadCreate(osThread(ThreadB),NULL);
         osKernelStart();
    
    ThreadC_id = osThreadCreate(osThread(ThreadA), NULL); 
        osKernelStart();
    ...
    ...
    }
    So, i want to use the return value of temp_buffer from ThreadB into Thread C and want to put this value to TXBuf in ThreadA...

    any help would be highly appreciated
    Thanks

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    You could use a mutex as a status ready indicator, or if you want to be able to queue up statuses, then perhaps mutexes (for temporary ownership during queue updates), semaphores (for count of elements on a queue), and some type of queueing method (circular buffer or linked list).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Threaded callbacks...
    By megrez80 in forum C Programming
    Replies: 2
    Last Post: 11-29-2011, 11:56 AM
  2. Going from single-threaded to multi-threaded
    By Dino in forum C Programming
    Replies: 11
    Last Post: 03-23-2008, 01:14 PM
  3. Threaded models under VC++?
    By zopiro in forum C++ Programming
    Replies: 1
    Last Post: 05-30-2007, 11:42 PM
  4. multi threaded program
    By Dash_Riprock in forum C++ Programming
    Replies: 6
    Last Post: 08-27-2006, 08:38 AM
  5. Threaded program
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 03-02-2002, 01:00 PM

Tags for this Thread