Opened 11 years ago
Closed 11 years ago
#5845 closed Support Requests (invalid)
mutex.inl: wait_mutex (and its callers) ignore failures from WaitForSingleObject
| Reported by: | Owned by: | viboes | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | thread | 
| Version: | Boost 1.47.0 | Severity: | Problem | 
| Keywords: | Cc: | noloader@…, viboes | 
Description
inline int wait_mutex(void* mutex, int time)
{
  unsigned int res = 0;
  res = WaitForSingleObject(mutex_cast(mutex), time);
  //:xxx    assert(res != WAIT_FAILED && res != WAIT_ABANDONED);
  return res;
}
Its callers are spread across a number of files, including mutex.cpp and recursive_mutex.cpp. Unfortunately, a common use case is shown below (taken from mutex.cpp):
void timed_mutex::do_lock()
{
   wait_mutex(m_mutex, INFINITE);
}
Not only does do_lock() ignore the return value, its callers will proceed to use the guarded data regardless of whether the lock was actually acquired.
do_trylock() does a little better, but still ignores return values such as ERROR_INVALID_HANDLE and WAIT_FAILED.
bool timed_mutex::do_trylock()
{
  return wait_mutex(m_mutex, 0) == WAIT_OBJECT_0;
}
      Change History (3)
comment:1 by , 11 years ago
| Cc: | added | 
|---|---|
| Component: | None → thread | 
| Owner: | set to | 
comment:2 by , 11 years ago
| Cc: | added | 
|---|---|
| Owner: | changed from to | 
| Status: | new → assigned | 
| Type: | Bugs → Support Requests | 
Sorry, I don't see any file mutex.inl. Moved to support request until concerned file clarified.
comment:3 by , 11 years ago
| Resolution: | → invalid | 
|---|---|
| Status: | assigned → closed | 
Closed as it seems these doesn't corresponds to the current Boost.Thread implementation.


assert(res == WAIT_OBJECT_0)might be too tight -assert(res == WAIT_OBJECT_0 || res == WAIT_ABANDONED_0)might be a better choice.