Opened 10 years ago

Closed 10 years ago

#8443 closed Bugs (fixed)

Header file inclusion order may cause crashes

Reported by: Nathan Crookston <nathan.crookston+boost@…> Owned by: viboes
Milestone: Boost 1.54.0 Component: thread
Version: Boost Release Branch Severity: Problem
Keywords: Cc:

Description

pthread/mutex.hpp and pthread/recursive_mutex.hpp both attempt to define the macro BOOST_PTHREAD_HAS_TIMEDLOCK. They each have different conditions for when to define it, which results in different cpp files thinking certain objects are different sizes, and it (hopefully) crashes.

While it would be good to provide logic for defining the symbol in one place (mutex.hpp was most recently updated for #3639), I believe that both conditions are wrong:

#ifdef _POSIX_TIMEOUTS
#if _POSIX_TIMEOUTS >= 0
#define BOOST_PTHREAD_HAS_TIMEDLOCK
#endif
#endif

and

#ifdef _POSIX_TIMEOUTS
#if _POSIX_TIMEOUTS >= 0 && _POSIX_C_SOURCE>=200112L
#define BOOST_PTHREAD_HAS_TIMEDLOCK
#endif
#endif

I think using _POSIX_C_SOURCE is not right. On our platform (solaris variant), _POSIX_C_SOURCE == 199506L, but _POSIX_TIMEOUTS == 200112L and pthread_mutex_timedlock is available.

Thus, I suggest using the following for both conditions (and hopefully testing the condition in one place):

#if defined(_POSIX_TIMEOUTS) && _POSIX_TIMEOUTS >= 200112L
#define BOOST_PTHREAD_HAS_TIMEDLOCK
#endif

This problem is in trunk starting with at least 1.49, and remains in the current version, as well as trunk.

Change History (7)

comment:1 by Nathan Crookston <nathan.crookston+boost@…>, 10 years ago

Here's an example of checking the _POSIX_TIMEOUTS variable as suggested above: http://lists.apple.com/archives/unix-porting/2008/Jan/msg00014.html

comment:2 by viboes, 10 years ago

Owner: changed from Anthony Williams to viboes
Status: newassigned

comment:3 by viboes, 10 years ago

Milestone: To Be DeterminedBoost 1.54.0

Committed revision [83948].

comment:4 by Nathan Crookston <nathan.crookston+boost@…>, 10 years ago

Hi Vicente,

Thanks for fixing the different conditions to define BOOST_PTHREAD_HAS_TIMEDLOCK. In my note, I mentioned that using _POSIX_C_SOURCE isn't likely the right thing -- using _POSIX_TIMEOUTS should be.

Is there a reason to continue to use _POSIX_C_SOURCE?

in reply to:  4 comment:5 by viboes, 10 years ago

Replying to Nathan Crookston <nathan.crookston+boost@…>:

Hi Vicente,

Thanks for fixing the different conditions to define BOOST_PTHREAD_HAS_TIMEDLOCK. In my note, I mentioned that using _POSIX_C_SOURCE isn't likely the right thing -- using _POSIX_TIMEOUTS should be.

Is there a reason to continue to use _POSIX_C_SOURCE?

Sorry, I missed this point. I will see if there is no regression with _POSIX_TIMEOUTS.

comment:6 by viboes, 10 years ago

Committed revision [83962].

comment:7 by viboes, 10 years ago

Resolution: fixed
Status: assignedclosed

(In [83993]) Thread: fix #8443.

Note: See TracTickets for help on using tickets.