Changeset 35:f8a5b321d0c3 in xplcommon for src/xplcommon/posix/Thread.cc


Ignore:
Timestamp:
01/03/13 06:57:15 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added support for detached threads

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/xplcommon/posix/Thread.cc

    r3 r35  
    4040void* Thread::threadFn(void* arg)
    4141{
    42     reinterpret_cast<Thread*>(arg)->run();
     42    Thread* thread = reinterpret_cast<Thread*>(arg);
     43    thread->run();
     44    if (thread->detached) delete thread;
    4345    return 0;
     46}
     47
     48//------------------------------------------------------------------------------
     49
     50bool Thread::start()
     51{
     52    pthread_attr_t attr;
     53    pthread_attr_init(&attr);
     54    pthread_attr_setdetachstate(&attr, detached ? PTHREAD_CREATE_DETACHED :
     55                                PTHREAD_CREATE_JOINABLE);
     56    bool isOK = pthread_create(&thread, &attr, &threadFn, this)>=0;
     57    pthread_attr_destroy(&attr);
     58    return isOK;
    4459}
    4560
Note: See TracChangeset for help on using the changeset viewer.