The flags thread attribute

QNX SDP8.0Getting Started with the QNX OSDeveloperUser

Let's start with the boolean thread attributes.

  • To create a joinable thread (meaning that another thread can synchronize to its termination via pthread_join()), you'd use pthread_attr_setdetachstate() like this:
    (default)
    pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_JOINABLE);
    
    To create one that can't be joined (called a detached thread), you'd use this:
    pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
    
  • If you want the thread to inherit the scheduling attributes of the creating thread (that is, to have the same scheduling policy and the same priority), you'd use pthread_attr_setinheritsched() like this:
    (default)
    pthread_attr_setinheritsched (&attr, PTHREAD_INHERIT_SCHED);
    
    To create one that uses the scheduling attributes specified in the attribute structure itself (which you'd set using pthread_attr_setschedparam() and pthread_attr_setschedpolicy()), you'd use this:
    pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED);
    
  • If you don't want the thread to be put into a suspended state when it's created, you'd call pthread_attr_setsuspendstate_np() like this:
    (default)
    pthread_attr_setsuspendstate_np (&attr, PTHREAD_NOT_SUSPENDED);
    
    If you want the thread to be suspended when it's created, you'd use this:
    pthread_attr_setsuspendstate_np (&attr, PTHREAD_SUSPENDED);
    
  • Finally, you should never call pthread_attr_setscope(). Why? Because QNX OS supports only system scope, and it's the default when you initialize the attribute. (System scope means that all threads in the system compete against each other for CPU; the other value, process, means that threads compete against each other for CPU within the process, and the kernel schedules the processes.)
    If you do insist on calling it, you can call it only as follows:
    (default)
    pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
    
Page updated: