Bug #30992 Wrong implementation of pthread_mutex_trylock()
Submitted: 13 Sep 2007 7:55 Modified: 24 Oct 2007 19:31
Reporter: Mats Kindahl Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.0 OS:Any
Assigned to: Magnus BlÄudd CPU Architecture:Any

[13 Sep 2007 7:55] Mats Kindahl
Description:
Pthread_mutex_trylock() should return immediately if it cannot acquire the lock. This is not the behaviour when using safe_mutex(), which attempts to lock the mutex in the same manner as pthread_mutex_lock().

Pthread_mutex_trylock() should also return EBUSY when the lock cannot be acquired, but this is not the case when compiling for windows, where it is defined to return either 0 or 1.

How to repeat:
Read the code

Suggested fix:
Fix the windows mapping to return the correct constant.

Fix the implementation of safe_mutex to be able to return immediately if the lock is already locked.
[13 Sep 2007 15:07] Miguel Solorzano
Thank you for the bug report.
[3 Oct 2007 19:38] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/34856

ChangeSet@1.2526, 2007-10-03 21:38:32+02:00, msvensson@pilot.mysql.com +2 -0
  Bug#30992 Wrong implementation of pthread_mutex_trylock()
  It's not possible to use WaitForSingleObject to wait
  on a CRITICAL_SECTION, instead use the TryEnterCriticalSection function.
   - if "mutex" was already taken => return EBUSY
   - if "mutex" was aquired => return 0
[19 Oct 2007 18:52] Bugs System
Pushed into 5.1.23-beta
[19 Oct 2007 18:54] Bugs System
Pushed into 5.0.52
[24 Oct 2007 19:31] Paul Dubois
Noted in 5.0.52, 5.1.23 changelogs.