This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

what is meant by mutexes and semaphore?


Please let know

1.what is meant by mutexes and semaphore?

2.what is the role of these in threadx?

  • As per my knowledge,

    Mutexes - it protect the resource. example : if there is an multiple thread,then it will execute the thread one by one,if that thread execution complete,then next thread start execute.

    semaphore - it will execute n number threads(depends on ram). Each thread will execute at certain or particular time.

    If anything wrong ,please explain me with real world concept it helps me to understand sweetly.

  • A mutex is indeed used to lock a resource to a single thread. If you are using some hardware periphery like a UART or I2C e.g., you would use a mutex to let one thread have exclusive access to that resource. The I2C framwork incorporates this already, you could use


    and make the thread wait until it has gained access to the I2C bus to use it for whatever you desire. afterwards, you will of course have to unlock it again to give other threads the chance to use the periphery.

    A semaphore on the other hand can be used for signalling between threads or between a callback function and a thread. A simple example here is the usage of the USB framework, where a semaphore is used to let the USB thread know that a PC has been connected via the callback function 

    void ux_cdc_device0_instance_activate (VOID * cdc_instance)
        /* Save the CDC instance.  */
        g_cdc = (UX_SLAVE_CLASS_CDC_ACM *) cdc_instance;

    where the USB thread would wait for the sempahore g_cdc_activate_semaphore0 to get a value with

    tx_semaphore_get (&g_cdc_activate_semaphore0, TX_WAIT_FOREVER);

    and only begin to run when the semaphore has been put through the callback function.

    If there are more questions left, don't hesitate to ask.

    Kind Regards,


  • Hi Christoph,

    sweet explanation,i understand about mutex. In semaphore,what is that meant by "signalling between threads or callback function"? 

  • Like I already explained, you can make a thread wait for a certain event with it (like the activation of the USB CDC class).

    Another example: You are using a UART to communicate with a peripheral IC. When you used the write command of the UART driver, after the writing has completed, an event will fire in your UART callback with the code UART_EVENT_TX_COMPLETE. This signals to you that another transmission can be started. On this event, you could call a PUT into a semaphore which you can try to GET before writing more data onto the UART. Through this, the callback function signals a thread that the writing has finished and another writing can be started. To sum it up:

    //this here is the write function, which waits until the semaphore has been filled by the callback
    //the semaphore is initialized to '1' when the controller starts, so that the first transmission can be sent
    void write_uart5(void)
    	g_uart5.p_api->write(g_uart5.p_ctrl,(UCHAR*)SEND,send_buffer_ptr); //SEND is the data buffer
    //UART callback function, gets called whenever there is an event within the UART periphery
    void uart5_callback(uart_callback_args_t *p_args)
    		case UART_EVENT_RX_CHAR:
    			TEL[TEL_PTR++]=(UCHAR)p_args->data;                             //TEL is the receive data buffer
    			if(TEL[TEL_PTR-1]==0x0A && TEL[TEL_PTR-2]==0x0D)				//End of Telegram

  • There are a LOT of references for those types of questions on the web. This group is for Synergy-related issues on Renesas processors. ThreadX (now  Azure RTOS) is a Microsoft-supported product.

  • okay larry_c_mass