This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

mutex using LCK vs SEM

From some of the BIOS documentations I have read, it seems that LCK_pend/post is a safer way to achieve mutual exclusion comparing to a SEM_pend/post. Are there specific cases where one is better suited than the other?

Thanks,

Saj

 

 

  • I wouldn't necessarily say that using LCK is safer than using SEM, since with either one you can get into trouble with unbalanced pends and posts.   In fact, LCK uses SEM internally.  The advantage of the LCK module is that the holder of the LCK can re-enter the lock, which is a benefit in situations where a TSK acquires a LCK, and while holding the LCK it calls another function which internally acquires the same LCK.

        LCK_Handle lock;

        int tsk_fxn()
        {
            LCK_pend(lock);
            foo();
            LCK_post(lock);
        }

        void foo(void)
        {
            LCK_pend(lock);
            ...
            LCK_post(lock);
        }

    The above situation works, while if it used SEM instead it would block on the pend call in the function foo().

    Regards,

    - Rob