Mutex binary binary counting failures

I ran an example C ++ program on the vxWorks platform to check the time difference between a mutex and a binary semaphore. The program below is a prototype.

SEM ID semMutex;
UINT ITER = 10000;
taskIdOne = TASKSPAWN("t1",TASK_PRIORITY_2,0,8192,0,(FUNCPTR)myMutexMethod,0,0);
taskIdTwo = TASKSPAWN("t2",TASK_PRIORITY_2,0,8192,0,(FUNCPTR)myMutexMethod,0,0);
void myMutexMethod(void)
    {
        int i;
        VKI_PRINTF("I'm  (%s)\n",TASKNAME(0) );
        myMutexTimer.start();
        for (i=0; i < ITER; i++)
        {
            MUTEX_LOCK(semMutex,WAIT_FOREVER); 
            ++global;                     
            MUTEX_UNLOCK(semMutex); 
        } 
        myMutexTimer.stop();
        myMutexTimer.show();
    }

There is a conflict in the above program (2 tasks are trying to get a mutex). my timer printed 37.43 ms for the above program. In the same prototype, a binary semaphore program took only 2.8 ms. This is understood because the binary semaphore is lightweight and does not have many functions, such as a mutex (priority inversion, ownership, etc.).

( ). , t1 , . .
mutex 3,35 4 .

, , , , .
? - ?

.!

+3
1

, , - , , . , (.. ). , , , , - , - , .

:

1) semTake(semMutex)
2) ++global;
3) semGive(semMutex) // sem owner flag is not changed
4) sameTake(semMutex) // from same task as previous semTake
...

4 semTake , sem owner == ( 1 ), .

, , vxworks , -, , vxworks.

, semMLib .

+1

All Articles