Skip to content

Commit 48a4a06

Browse files
committed
Fix Issue 275
* Re-fixed the EINTR bug that exists in some pthreads implementations. It was originally fixed in https://svn.boost.org/trac10/ticket/6200 and was accidentally disabled in 5b209c2. * Made sure that the fix for the EINTR bug was consistently applied to all code in the library. * Made sure that all pthread_mutex_*() and pthread_cond_*() function calls in the library were consistently decorated with BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS.
1 parent f90bdfd commit 48a4a06

11 files changed

Lines changed: 250 additions & 186 deletions

include/boost/thread/pthread/condition_variable.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ namespace boost
7676
detail::interruption_checker check_for_interruption(&internal_mutex,&cond);
7777
pthread_mutex_t* the_mutex = &internal_mutex;
7878
guard.activate(m);
79-
res = pthread_cond_wait(&cond,the_mutex);
79+
res = posix::pthread_cond_wait(&cond,the_mutex);
8080
check_for_interruption.unlock_if_locked();
8181
guard.deactivate();
8282
#else
8383
pthread_mutex_t* the_mutex = m.mutex()->native_handle();
84-
res = pthread_cond_wait(&cond,the_mutex);
84+
res = posix::pthread_cond_wait(&cond,the_mutex);
8585
#endif
8686
}
8787
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
8888
this_thread::interruption_point();
8989
#endif
90-
if(res && res != EINTR)
90+
if(res)
9191
{
9292
boost::throw_exception(condition_error(res, "boost::condition_variable::wait failed in pthread_cond_wait"));
9393
}
@@ -119,12 +119,12 @@ namespace boost
119119
detail::interruption_checker check_for_interruption(&internal_mutex,&cond);
120120
pthread_mutex_t* the_mutex = &internal_mutex;
121121
guard.activate(m);
122-
cond_res=pthread_cond_timedwait(&cond,the_mutex,&timeout.getTs());
122+
cond_res=posix::pthread_cond_timedwait(&cond,the_mutex,&timeout.getTs());
123123
check_for_interruption.unlock_if_locked();
124124
guard.deactivate();
125125
#else
126126
pthread_mutex_t* the_mutex = m.mutex()->native_handle();
127-
cond_res=pthread_cond_timedwait(&cond,the_mutex,&timeout.getTs());
127+
cond_res=posix::pthread_cond_timedwait(&cond,the_mutex,&timeout.getTs());
128128
#endif
129129
}
130130
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
@@ -146,15 +146,15 @@ namespace boost
146146
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
147147
boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
148148
#endif
149-
BOOST_VERIFY(!pthread_cond_signal(&cond));
149+
BOOST_VERIFY(!posix::pthread_cond_signal(&cond));
150150
}
151151

152152
inline void condition_variable::notify_all() BOOST_NOEXCEPT
153153
{
154154
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
155155
boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
156156
#endif
157-
BOOST_VERIFY(!pthread_cond_broadcast(&cond));
157+
BOOST_VERIFY(!posix::pthread_cond_broadcast(&cond));
158158
}
159159

160160
class condition_variable_any
@@ -166,22 +166,22 @@ namespace boost
166166
BOOST_THREAD_NO_COPYABLE(condition_variable_any)
167167
condition_variable_any()
168168
{
169-
int const res=pthread_mutex_init(&internal_mutex,NULL);
169+
int const res=posix::pthread_mutex_init(&internal_mutex);
170170
if(res)
171171
{
172172
boost::throw_exception(thread_resource_error(res, "boost::condition_variable_any::condition_variable_any() failed in pthread_mutex_init"));
173173
}
174-
int const res2 = pthread::cond_init(cond);
174+
int const res2 = posix::pthread_cond_init(&cond);
175175
if(res2)
176176
{
177-
BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
178-
boost::throw_exception(thread_resource_error(res2, "boost::condition_variable_any::condition_variable_any() failed in pthread::cond_init"));
177+
BOOST_VERIFY(!posix::pthread_mutex_destroy(&internal_mutex));
178+
boost::throw_exception(thread_resource_error(res2, "boost::condition_variable_any::condition_variable_any() failed in pthread_cond_init"));
179179
}
180180
}
181181
~condition_variable_any()
182182
{
183-
BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
184-
BOOST_VERIFY(!pthread_cond_destroy(&cond));
183+
BOOST_VERIFY(!posix::pthread_mutex_destroy(&internal_mutex));
184+
BOOST_VERIFY(!posix::pthread_cond_destroy(&cond));
185185
}
186186

187187
template<typename lock_type>
@@ -196,7 +196,7 @@ namespace boost
196196
boost::pthread::pthread_mutex_scoped_lock check_for_interruption(&internal_mutex);
197197
#endif
198198
guard.activate(m);
199-
res=pthread_cond_wait(&cond,&internal_mutex);
199+
res=posix::pthread_cond_wait(&cond,&internal_mutex);
200200
check_for_interruption.unlock_if_locked();
201201
guard.deactivate();
202202
}
@@ -438,13 +438,13 @@ namespace boost
438438
void notify_one() BOOST_NOEXCEPT
439439
{
440440
boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
441-
BOOST_VERIFY(!pthread_cond_signal(&cond));
441+
BOOST_VERIFY(!posix::pthread_cond_signal(&cond));
442442
}
443443

444444
void notify_all() BOOST_NOEXCEPT
445445
{
446446
boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
447-
BOOST_VERIFY(!pthread_cond_broadcast(&cond));
447+
BOOST_VERIFY(!posix::pthread_cond_broadcast(&cond));
448448
}
449449
private:
450450

@@ -471,7 +471,7 @@ namespace boost
471471
boost::pthread::pthread_mutex_scoped_lock check_for_interruption(&internal_mutex);
472472
#endif
473473
guard.activate(m);
474-
res=pthread_cond_timedwait(&cond,&internal_mutex,&timeout.getTs());
474+
res=posix::pthread_cond_timedwait(&cond,&internal_mutex,&timeout.getTs());
475475
check_for_interruption.unlock_if_locked();
476476
guard.deactivate();
477477
}

include/boost/thread/pthread/condition_variable_fwd.hpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,35 +58,31 @@ namespace boost
5858
// above) and must be initialized (etc) in case some
5959
// compilation units provide interruptions and others
6060
// don't.
61-
res=pthread_mutex_init(&internal_mutex,NULL);
61+
res=posix::pthread_mutex_init(&internal_mutex);
6262
if(res)
6363
{
6464
boost::throw_exception(thread_resource_error(res, "boost::condition_variable::condition_variable() constructor failed in pthread_mutex_init"));
6565
}
6666
//#endif
67-
res = pthread::cond_init(cond);
67+
res = posix::pthread_cond_init(&cond);
6868
if (res)
6969
{
7070
//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
7171
// ditto
72-
BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
72+
BOOST_VERIFY(!posix::pthread_mutex_destroy(&internal_mutex));
7373
//#endif
74-
boost::throw_exception(thread_resource_error(res, "boost::condition_variable::condition_variable() constructor failed in pthread::cond_init"));
74+
boost::throw_exception(thread_resource_error(res, "boost::condition_variable::condition_variable() constructor failed in pthread_cond_init"));
7575
}
7676
}
7777
~condition_variable()
7878
{
7979
int ret;
8080
//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
8181
// ditto
82-
do {
83-
ret = pthread_mutex_destroy(&internal_mutex);
84-
} while (ret == EINTR);
82+
ret = posix::pthread_mutex_destroy(&internal_mutex);
8583
BOOST_ASSERT(!ret);
8684
//#endif
87-
do {
88-
ret = pthread_cond_destroy(&cond);
89-
} while (ret == EINTR);
85+
ret = posix::pthread_cond_destroy(&cond);
9086
BOOST_ASSERT(!ret);
9187
}
9288

include/boost/thread/pthread/mutex.hpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333

3434
#include <boost/config/abi_prefix.hpp>
3535

36-
#ifndef BOOST_THREAD_HAS_NO_EINTR_BUG
37-
#define BOOST_THREAD_HAS_EINTR_BUG
38-
#endif
39-
4036
namespace boost
4137
{
4238

@@ -49,7 +45,7 @@ namespace boost
4945

5046
mutex()
5147
{
52-
int const res=pthread_mutex_init(&m,NULL);
48+
int const res=posix::pthread_mutex_init(&m);
5349
if(res)
5450
{
5551
boost::throw_exception(thread_resource_error(res, "boost:: mutex constructor failed in pthread_mutex_init"));
@@ -84,11 +80,7 @@ namespace boost
8480

8581
bool try_lock() BOOST_THREAD_TRY_ACQUIRE(true)
8682
{
87-
int res;
88-
do
89-
{
90-
res = posix::pthread_mutex_trylock(&m);
91-
} while (res == EINTR);
83+
int res = posix::pthread_mutex_trylock(&m);
9284
if (res==EBUSY)
9385
{
9486
return false;
@@ -124,17 +116,17 @@ namespace boost
124116
BOOST_THREAD_NO_COPYABLE(timed_mutex)
125117
timed_mutex()
126118
{
127-
int const res=pthread_mutex_init(&m,NULL);
119+
int const res=posix::pthread_mutex_init(&m);
128120
if(res)
129121
{
130122
boost::throw_exception(thread_resource_error(res, "boost:: timed_mutex constructor failed in pthread_mutex_init"));
131123
}
132124
#ifndef BOOST_THREAD_USES_PTHREAD_TIMEDLOCK
133-
int const res2=pthread::cond_init(cond);
125+
int const res2=posix::pthread_cond_init(&cond);
134126
if(res2)
135127
{
136128
BOOST_VERIFY(!posix::pthread_mutex_destroy(&m));
137-
boost::throw_exception(thread_resource_error(res2, "boost:: timed_mutex constructor failed in pthread::cond_init"));
129+
boost::throw_exception(thread_resource_error(res2, "boost:: timed_mutex constructor failed in pthread_cond_init"));
138130
}
139131
is_locked=false;
140132
#endif
@@ -143,7 +135,7 @@ namespace boost
143135
{
144136
BOOST_VERIFY(!posix::pthread_mutex_destroy(&m));
145137
#ifndef BOOST_THREAD_USES_PTHREAD_TIMEDLOCK
146-
BOOST_VERIFY(!pthread_cond_destroy(&cond));
138+
BOOST_VERIFY(!posix::pthread_cond_destroy(&cond));
147139
#endif
148140
}
149141

@@ -203,11 +195,7 @@ namespace boost
203195

204196
bool try_lock()
205197
{
206-
int res;
207-
do
208-
{
209-
res = posix::pthread_mutex_trylock(&m);
210-
} while (res == EINTR);
198+
int res = posix::pthread_mutex_trylock(&m);
211199
if (res==EBUSY)
212200
{
213201
return false;
@@ -261,7 +249,7 @@ namespace boost
261249
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
262250
while(is_locked)
263251
{
264-
int const cond_res=pthread_cond_timedwait(&cond,&m,&timeout.getTs());
252+
int const cond_res=posix::pthread_cond_timedwait(&cond,&m,&timeout.getTs());
265253
if(cond_res==ETIMEDOUT)
266254
{
267255
break;

0 commit comments

Comments
 (0)