Differentiating between Binary semaphore and Mutex using same code -


void forward(void *pvparam) {     while(1)     {         if(xsemaphoretake(xsemaphore,1000)==pdtrue)         {             uart0_sendstr("frwd took it\n");         }         else         {              uart0_sendstr("frwd couldn't take it\n");         }         vtaskdelay(1000);     } }  void back(void *pvparam) {     vtaskdelay(100);     while(1)     {         if(xsemaphoregive(xsemaphore)==pdtrue)         {             uart0_sendstr("back gave it:mf\n");         }         else         {              uart0_sendstr("back couldn't give it:ms\n");         }         vtaskdelay(1000);     } } 

above code 1 using both binary semaphore , mutex. difference binary semaphore writing "xsemaphorecreatebinary(xsemaphore);" in main , mutex xsemaphorecreatemutex(xsemaphore) in main.

according definetion

"a semaphore(mutex) occupied task can given task , semaphore(binary) created task can given of tasks"

but both codes(i.e binary semaphore , mutex) giving same output.

mutexes used controlling exclusive access resources / data. if take mutex protecting resource / data, must give when have finished, otherwise permanently block resource. mutexes allow priority inheritance.

binary semaphores on other hand used task synchronization purposes. not give give semaphore once have taken it.

looking @ code above think binary semaphore way go.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -