Forums > Dev

systhread_mutex_lock vs systhread_mutex_trylock

Jan 11 2012 | 10:29 am

What is the best way of choosing between mutex_lock and mutex_trylock?
What does mutex_lock do when the mutex is already locked? does it wait?

I looked at the ‘collect’ example and there is no mention of mutex_trylock. Is that on purpose?



Feb 01 2012 | 1:51 pm

Hello vanille,

you’re right
thanks for the response, sorry for my delay in responding

I did a little test and yes, the mutex_lock sleeps the current thread. Another thread can still unlock it.


Feb 01 2012 | 5:20 pm

curious: what is your recipe for delaying the message inside the external?

Feb 02 2012 | 12:56 am

FWIW I also use lightweight thread sync stuff based on atomic operations a lot of the time, including when I need to wait till the lock is free. In this case you can spin on a while loop until it is free or similar . The thread will be consuming cycles, but that is often IMHO preferable to sleeping threads for short periods in real-time contexts…


Feb 02 2012 | 7:06 am

interesting, thanks guys.

alex, why is in your opinion spinning on a while loop preferred to sleeping a thread?
isn’t that basically the same thing? or do I miss something.

Viewing 5 posts - 1 through 5 (of 5 total)

Forums > Dev