Skip to content

Commit 461ad03

Browse files
Merge branch 'iss-49' into develop
2 parents 255d849 + 07c0f1a commit 461ad03

File tree

5 files changed

+32
-30
lines changed

5 files changed

+32
-30
lines changed

include/pthread/thread.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,9 @@ namespace pthread {
122122
*
123123
* This method does not itself cause a thread to be terminated.
124124
*
125-
* @return the value returned by the joined thread (calling pthread_exit(void *retval))
126125
* @throws pthread_exception if this is not a thread or if thread_id == this_thread::get_id().
127126
*/
128-
void *join();
127+
void join();
129128

130129
/** @return true if this thread can be joined.
131130
*/
@@ -246,14 +245,13 @@ namespace pthread {
246245

247246
/** joins this thread.
248247
*
249-
* @return value returned by the joined thread (pthread_exit(void *retval))
250248
* @throw pthread_exception if deadlock conditions are detected.
251249
*/
252-
void *join() { return _thread->join() ;};
250+
void join() ;
253251

254252
/** @return true if this thread can be joined.
255253
*/
256-
bool joinable() const { return _thread != 0 ;};
254+
bool joinable() const ;
257255

258256

259257
private:

src/thread.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,9 @@ namespace pthread {
2323
}
2424
}
2525

26-
void *thread::join () {
27-
int rc = 0;
28-
void *retval = 0;
26+
void thread::join () {
2927

30-
#if __cplusplus < 201103L
31-
if ( _thread != NULL){
32-
#else
33-
if ( _thread != nullptr){
34-
#endif
28+
if ( _thread != 0){
3529

3630
if ( _thread == this_thread::get_id()){
3731
throw pthread_exception("join failed, join yourself would endup in deadlock.");
@@ -41,7 +35,12 @@ namespace pthread {
4135
throw pthread_exception("join failed, this is not a thread.");
4236
}
4337

44-
if ( (rc = pthread_join(_thread, (void **)&retval)) != 0){
38+
int rc = 0;
39+
if ( (rc = pthread_join(_thread, NULL)) == 0){
40+
// thread was successfully joined, it's safe to assume that it's not a thread anymore.
41+
_status = thread_status::not_a_thread ;
42+
_thread = 0;
43+
} else {
4544
switch ( rc ) {
4645
case EDEADLK:
4746
throw thread_exception("EDEADLKpthread_join failed because of deadlock conditions.", rc );
@@ -50,9 +49,9 @@ namespace pthread {
5049
case ESRCH:
5150
break; // thread has already ended.
5251
}
53-
}
52+
53+
}
5454
}
55-
return retval;
5655
}
5756

5857
int thread::cancel () {
@@ -135,6 +134,14 @@ namespace pthread {
135134
_thread = new pthread::thread(*this, _stack_size);
136135
}
137136

137+
void abstract_thread::join() {
138+
return _thread->join() ;
139+
};
140+
141+
bool abstract_thread::joinable() const {
142+
return _thread != 0 ;
143+
};
144+
138145
#if __cplusplus < 201103L
139146
thread_group::thread_group(bool destructor_joins_first) throw(): _destructor_joins_first(destructor_joins_first){
140147
#else
@@ -194,12 +201,13 @@ namespace pthread {
194201
run method on the thread object passed to it (as a void *).
195202
*/
196203
void *thread_startup_runnable(void *runner) {
197-
198-
static_cast<runnable *>(runner)->run();
199-
200-
return (NULL);
204+
205+
try{
206+
static_cast<runnable *>(runner)->run();
207+
} catch ( ... ) {
208+
printf("uncaugth excpetion in thread_startup_runnable(), check your runnable::run() implementation.");
209+
}
210+
return NULL ;
201211
}
202212

203-
// exception -------
204-
205213
} // namespace pthread

tests/Makefile.in

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,12 @@ MV=@MV@
2323

2424
BITS=@BITS@
2525
OBJECT_MODE=$(BITS)
26-
LIBS=@LIBS@
27-
28-
#DEBUG=-g -bnoquiet
29-
#PROFILER=-p
3026

3127
CXXFLAGS=@CXXFLAGS@
3228
CFLAGS=@CFLAGS@
3329
CPPFLAGS=@CPPFLAGS@
34-
3530
LDFLAGS=@LDFLAGS@
31+
LIBS=@LIBS@
3632

3733
OBJECTS=without-cpp11-pthread-tests.o
3834
TARGETS=without-cpp11-pthread-tests exceptions-tests
@@ -42,7 +38,7 @@ all:${TARGETS}
4238
clean: globber
4339

4440
globber:
45-
${RM} *.o core *.a *.out
41+
${RM} *.o core core.* *.a *.out
4642
${RM} ${TARGETS}
4743
$(RM) *unc-backup*~ *unc-backup*~
4844
$(RM) ULOG*

tests/configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3743,7 +3743,7 @@ $as_echo_n "checking for specific $CXX compiler options... " >&6; }
37433743
case "$CXX" in
37443744
xlC_r | xlC)
37453745
CPPFLAGS="-qlanglvl=extended0x:decltype:static_assert:rvaluereferences:rvaluereferences -qsourcetype=c++ -O $CPPFLAGS"
3746-
CFLAGS="-bh:5 -O -qmaxmem=-1 -q$BITS $CFLAGS"
3746+
CFLAGS="-g -bh:5 -O -qmaxmem=-1 -q$BITS $CFLAGS"
37473747
LDFLAGS="$LDFLAGS -brtl -bmaxdata:0x80000000"
37483748
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: using large memory model (maxdata:0x80000000), optimising level 2 (-O),using run-time link method (-brtl)" >&5
37493749
$as_echo "using large memory model (maxdata:0x80000000), optimising level 2 (-O),using run-time link method (-brtl)" >&6; }

tests/configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ AC_MSG_CHECKING([for specific $CXX compiler options])
4040
case "$CXX" in
4141
xlC_r | xlC)
4242
CPPFLAGS="-qlanglvl=extended0x:decltype:static_assert:rvaluereferences:rvaluereferences -qsourcetype=c++ -O $CPPFLAGS"
43-
CFLAGS="-bh:5 -O -qmaxmem=-1 -q$BITS $CFLAGS"
43+
CFLAGS="-g -bh:5 -O -qmaxmem=-1 -q$BITS $CFLAGS"
4444
LDFLAGS="$LDFLAGS -brtl -bmaxdata:0x80000000"
4545
AC_MSG_RESULT([using large memory model (maxdata:0x80000000), optimising level 2 (-O),using run-time link method (-brtl)])
4646
;;

0 commit comments

Comments
 (0)