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: noloader@… 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 Jeffrey Walton <noloader@…>, 11 years ago

Cc: noloader@… added
Component: Nonethread
Owner: set to Anthony Williams

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

comment:2 by viboes, 11 years ago

Cc: viboes added
Owner: changed from Anthony Williams to viboes
Status: newassigned
Type: BugsSupport Requests

Sorry, I don't see any file mutex.inl. Moved to support request until concerned file clarified.

comment:3 by viboes, 11 years ago

Resolution: invalid
Status: assignedclosed

Closed as it seems these doesn't corresponds to the current Boost.Thread implementation.

Note: See TracTickets for help on using tickets.