Opened 15 years ago
Closed 15 years ago
#5336 closed bug (fixed)
pthread_mutex_trylock() hangs
Reported by: | kaliber | Owned by: | nobody |
---|---|---|---|
Priority: | normal | Milestone: | R1 |
Component: | System/POSIX | Version: | R1/Development |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
If a mutex is already locked, pthread_mutex_trylock() should return EBUSY instead of hanging.
Specification: http://www.opengroup.org/onlinepubs/000095399/functions/pthread_mutex_lock.html
Change History (5)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
I've looked into this problem a bit, but I am not quite sure why the pthread_mutex_trylock() implementation is the problem (also from talking to Axel). I understand that by doing what it does, it potentially converts a benaphore style mutex into a semaphore based one. Is the hanging problem then in the kernel implementation with the 0 absolute timeout? If pthread_mutex_trylock() only touches the count, how would it work when the mutex has alreasy been converted to be semaphore based?
follow-up: 4 comment:3 by , 15 years ago
The WebCore trylock asserts work now (don't hang a WebPositive debug build on start-up anymore). Kaliber, can you please check if this bug is fixed for your test-cases as well?
comment:4 by , 15 years ago
Replying to stippi:
The WebCore trylock asserts work now (don't hang a WebPositive debug build on start-up anymore). Kaliber, can you please check if this bug is fixed for your test-cases as well?
Yes, it's fixed.
Confirmed. The pthread_mutex_trylock() implementation is incorrect. It should not even touch the semaphore, but instead use atomic_test_and_set() on the count. Moreover the kernel's thread_block_with_timeout_locked() needs to check for an overflow in case B_TIMEOUT_REAL_TIME_BASE is set.