Ticket #6058 (closed Bugs: fixed)

Opened 6 years ago

Last modified 5 years ago

semaphore_timed_wait() behaviour inconsistent with glibc sem_timedwait()

Reported by: Frank <frank.kusters@…> Owned by: igaztanaga
Milestone: To Be Determined Component: interprocess
Version: Boost Development Trunk Severity: Problem
Keywords: Cc: kees-jan.dijkzeul@…


What should boost::interprocess::interprocess_semaphore::timed_wait(abs_time) return when the absolute time it is given, is in the past, but the semaphore is available?

The boost documentation in interprocess_semaphore.hpp is not very clear, but it does suggest that it should return true.

The implementation in semaphore_wrapper.hpp does the following:

If BOOST_INTERPROCESS_POSIX_TIMEOUTS is defined, sem_timedwait() is called from semaphore.h. If the macro is not defined, it will use its own implementation, which first looks at the time, and will thus return false in this case. This is in contradiction with the documentation.

sem_timedwait in semaphore.c, however, will first try to acquire the lock, and if it could not get a lock, look at the time. Thus the end result will be true, which is inconsistent with the boost version.

Please note that the POSIX documentation is unclear on this topic too, so the semaphore.c implementation might vary from system to system. I am talking about the GNU version.


Change History

comment:1 Changed 6 years ago by kees-jan.dijkzeul@…

  • Cc kees-jan.dijkzeul@… added

comment:2 Changed 5 years ago by igaztanaga

I think your questions means a bug in Interprocess. According to

"Under no circumstance shall the function fail with a timeout if the semaphore can be locked immediately. The validity of the abs_timeout need not be checked if the semaphore can be locked immediately"

The implementation should not check the timeout before trying to lock the semaphore

comment:3 Changed 5 years ago by igaztanaga

  • Status changed from new to closed
  • Resolution set to fixed

Implementation changed in Trunk and Release branches, so that a lock try is performed before checking the timeout.


Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.