@@ -61,26 +61,24 @@ namespace pthread {
6161
6262 thread::thread (const runnable &work, const std::size_t stack_size ): thread(){ // ": thread()" calls the related anonymous constructor
6363 int rc = 0 ;
64- pthread_attr_t attr;
6564
6665 /* Initialize and set thread detached attribute */
67- if ( (rc = pthread_attr_init (&attr )) != 0 ){
66+ if ( (rc = pthread_attr_init (&_attr )) != 0 ){
6867 throw thread_exception (" pthread_attr_init failed." , rc );
6968 }
7069
71- if ( (rc = pthread_attr_setdetachstate (&attr , PTHREAD_CREATE_JOINABLE)) != 0 ){
70+ if ( (rc = pthread_attr_setdetachstate (&_attr , PTHREAD_CREATE_JOINABLE)) != 0 ){
7271 throw thread_exception (" pthread_attr_setdetachstate failed." , rc );
7372 }
7473
75- if ( stack_size > 0 && (rc = pthread_attr_setstacksize (&attr , stack_size)) != 0 ){
74+ if ( stack_size > 0 && (rc = pthread_attr_setstacksize (&_attr , stack_size)) != 0 ){
7675 throw thread_exception (" pthread_attr_setstacksize failed." , rc );
7776 }
7877
79- if ((rc = pthread_create (&_thread, &attr , thread_startup_runnable, (void *) &work)) != 0 ){
78+ if ((rc = pthread_create (&_thread, &_attr , thread_startup_runnable, (void *) &work)) != 0 ){
8079 throw thread_exception (" pthread_create failed." , rc );
8180 } else {
8281 _status = thread_status::a_thread;
83- pthread_attr_destroy (&attr);
8482 }
8583
8684 }
@@ -91,6 +89,10 @@ namespace pthread {
9189 swap (other);
9290 }
9391
92+ thread::~thread () {
93+ pthread_attr_destroy (&_attr);
94+ }
95+
9496 /* move operator */
9597 thread& thread::operator =(thread&& other){
9698
@@ -104,9 +106,6 @@ namespace pthread {
104106 std::swap (_status, other._status );
105107 }
106108
107- thread::~thread () {
108- }
109-
110109 abstract_thread::abstract_thread (const std::size_t stack_size): _stack_size(stack_size){
111110 }
112111
0 commit comments