MyWebUniversity.com Home Page
 



OpenSolaris man pages main menu


Standards, Environments, and Macros                    threads(5)



NAME
     threads, pthreads - POSIX pthreads and Solaris threads  con-
     cepts

SYNOPSIS
  POSIX
     cc -mt [ flag... ] file... [ -lrt library... ]


     #include 


  Solaris
     cc -mt [ flag... ] file... [ library... ]


     #include 


     #include 


DESCRIPTION
     POSIX and Solaris threads each have their own implementation
     within  libc(3LIB).  Both implementations are interoperable,
     their functionality similar, and can be used within the same
     application.  Only  POSIX threads are guaranteed to be fully
     portable to other POSIX-compliant  environments.  POSIX  and
     Solaris  threads require different source, include files and
     linking libraries. See SYNOPSIS.

  Similarities
     Most of the POSIX and Solaris threading functions have coun-
     terparts  with  each  other.  POSIX function names, with the
     exception of the semaphore names, have a  "pthread"  prefix.
     Function  names for similar POSIX and Solaris functions have
     similar endings. Typically, similar POSIX and Solaris  func-
     tions have the same number and use of arguments.

  Differences
     POSIX pthreads and Solaris threads differ in  the  following
     ways:

         o    POSIX threads are more portable.

         o    POSIX threads establish characteristics   for  each
              thread according to configurable attribute objects.

         o    POSIX pthreads implement thread cancellation.

         o    POSIX pthreads enforce scheduling algorithms.




SunOS 5.11          Last change: 11 Nov 2008                    1






Standards, Environments, and Macros                    threads(5)



         o    POSIX pthreads  allow  for  clean-up  handlers  for
              fork(2) calls.

         o    Solaris threads can be suspended and continued.

         o    Solaris threads implement daemon threads, for whose
              demise the process does not wait.

FUNCTION COMPARISON
     The following table compares the POSIX pthreads and  Solaris
     threads functions. When a comparable interface is not avail-
     able either in POSIX pthreads  or Solaris threads, a  hyphen
     (-) appears in the column.

  Functions Related to Creation
     POSIX                            Solaris
     pthreadcreate()                 thrcreate()
     pthreadattrinit()              -
     pthreadattrsetdetachstate()    -
     pthreadattrgetdetachstate()    -
     pthreadattrsetinheritsched()   -
     pthreadattrgetinheritsched()   -
     pthreadattrsetschedparam()     -
     pthreadattrgetschedparam()     -
     pthreadattrsetschedpolicy()    -
     pthreadattrgetschedpolicy()    -
     pthreadattrsetscope()          -
     pthreadattrgetscope()          -
     pthreadattrsetstackaddr()      -
     pthreadattrgetstackaddr()      -
     pthreadattrsetstacksize()      -
     pthreadattrgetstacksize()      -
     pthreadattrgetguardsize()      -
     pthreadattrsetguardsize()      -
     pthreadattrdestroy()           -
     -                                thrminstack()


  Functions Related to Exit
     POSIX                         Solaris
     pthreadexit()                threxit()
     pthreadjoin()                thrjoin()
     pthreaddetach()              -


  Functions Related to Thread Specific Data
     POSIX                         Solaris
     pthreadkeycreate()          thrkeycreate()
     pthreadsetspecific()         thrsetspecific()
     pthreadgetspecific()         thrgetspecific()
     pthreadkeydelete()          -




SunOS 5.11          Last change: 11 Nov 2008                    2






Standards, Environments, and Macros                    threads(5)



  Functions Related to Signals
     POSIX                         Solaris
     pthreadsigmask()             thrsigsetmask()
     pthreadkill()                thrkill()


  Functions Related to IDs
     POSIX                         Solaris
     pthreadself()                thrself()
     pthreadequal()               -
     -                             thrmain()


  Functions Related to Scheduling
     POSIX                         Solaris
     -                             thryield()
     -                             thrsuspend()
     -                             thrcontinue()
     pthreadsetconcurrency()      thrsetconcurrency()
     pthreadgetconcurrency()      thrgetconcurrency()
     pthreadsetschedparam()       thrsetprio()
     pthreadsetschedprio()        thrsetprio()
     pthreadgetschedparam()       thrgetprio()


  Functions Related to Cancellation
     POSIX                         Solaris
     pthreadcancel()              -
     pthreadsetcancelstate()      -
     pthreadsetcanceltype()       -
     pthreadtestcancel()          -
     pthreadcleanuppop()         -
     pthreadcleanuppush()        -


  Functions Related to Mutexes
     POSIX                                    Solaris
     pthreadmutexinit()                     mutexinit()
     pthreadmutexattrinit()                 -
     pthreadmutexattrsetpshared()           -
     pthreadmutexattrgetpshared()           -
     pthreadmutexattrsetprotocol()          -
     pthreadmutexattrgetprotocol()          -
     pthreadmutexattrsetprioceiling()       -
     pthreadmutexattrgetprioceiling()       -
     pthreadmutexattrsettype()              -
     pthreadmutexattrgettype()              -
     pthreadmutexattrsetrobust()            -
     pthreadmutexattrgetrobust()            -
     pthreadmutexattrdestroy()              -
     pthreadmutexsetprioceiling()           -
     pthreadmutexgetprioceiling()           -



SunOS 5.11          Last change: 11 Nov 2008                    3






Standards, Environments, and Macros                    threads(5)



     pthreadmutexlock()                     mutexlock()
     pthreadmutextrylock()                  mutextrylock()
     pthreadmutexunlock()                   mutexunlock()
     pthreadmutexdestroy()                  mutexdestroy()


  Functions Related to Condition Variables
     POSIX                           Solaris
     pthreadcondinit()             condinit()
     pthreadcondattrinit()         -
     pthreadcondattrsetpshared()   -
     pthreadcondattrgetpshared()   -
     pthreadcondattrdestroy()      -
     pthreadcondwait()             condwait()
     pthreadcondtimedwait()        condtimedwait()
     pthreadcondsignal()           condsignal()
     pthreadcondbroadcast()        condbroadcast()
     pthreadconddestroy()          conddestroy()


  Functions Related to Reader/Writer Locking
     POSIX                             Solaris
     pthreadrwlockinit()             rwlockinit()
     pthreadrwlockrdlock()           rwrdlock()
     pthreadrwlocktryrdlock()        rwtryrdlock()
     pthreadrwlockwrlock()           rwwrlock()
     pthreadrwlocktrywrlock()        rwtrywrlock()
     pthreadrwlockunlock()           rwunlock()
     pthreadrwlockdestroy()          rwlockdestroy()
     pthreadrwlockattrinit()         -
     pthreadrwlockattrdestroy()      -
     pthreadrwlockattrgetpshared()   -
     pthreadrwlockattrsetpshared()   -


  Functions Related to Semaphores
     POSIX                         Solaris
     seminit()                    semainit()
     semopen()                    -
     semclose()                   -
     semwait()                    semawait()
     semtrywait()                 sematrywait()
     sempost()                    semapost()
     semgetvalue()                -
     semunlink()                  -
     semdestroy()                 semadestroy()


  Functions Related to fork() Clean Up
     POSIX                         Solaris
     pthreadatfork()              -




SunOS 5.11          Last change: 11 Nov 2008                    4






Standards, Environments, and Macros                    threads(5)



  Functions Related to Limits
     POSIX                         Solaris
     pthreadonce()                -


  Functions Related to Debugging
     POSIX                         Solaris
     -                             thrstksegment()


LOCKING
  Synchronization
     Multithreaded  behavior  is  asynchronous,  and   therefore,
     optimized   for   concurrent  and  parallel  processing.  As
     threads, always from within the same process and   sometimes
     from  multiple processes, share global data with each other,
     they are not guaranteed exclusive access to the shared  data
     at  any point in time. Securing mutually exclusive access to
     shared data requires   synchronization  among  the  threads.
     Both   POSIX  and  Solaris  implement  four  synchronization
     mechanisms:  mutexes,  condition  variables,   reader/writer
     locking   (optimized  frequent-read occasional-write mutex),
     and semaphores.


     Synchronizing multiple threads diminishes their concurrency.
     The  coarser  the  grain  of  synchronization,  that is, the
     larger the block of code that is locked, the lesser the con-
     currency.

  MT fork()
     If a threads program  calls  fork(2),  it  implicitly  calls
     fork1(2),  which  replicates only the calling thread. Should
     there be any outstanding mutexes throughout the process, the
     application  should  call pthreadatfork(3C) to wait for and
     acquire those mutexes prior to calling fork().

SCHEDULING
  POSIX Threads
     Solaris supports the following three POSIX scheduling  poli-
     cies:

     SCHEDOTHER    Traditional Timesharing scheduling policy. It
                    is  based  on the timesharing (TS) scheduling
                    class.


     SCHEDFIFO     First-In-First-Out scheduling policy. Threads
                    scheduled to this policy, if not preempted by
                    a higher priority, will proceed until comple-
                    tion.  Such  threads  are  in  real-time (RT)
                    scheduling class. The  calling  process  must



SunOS 5.11          Last change: 11 Nov 2008                    5






Standards, Environments, and Macros                    threads(5)



                    have a effective user ID of 0.


     SCHEDR       Round-Robin   scheduling   policy.    Threads
                    scheduled to this policy, if not preempted by
                    a higher priority, will execute  for  a  time
                    period determined by the system. Such threads
                    are in real-time (RT)  scheduling  class  and
                    the  calling  process  must  have a effective
                    user ID of 0.



     In  addition  to  the  POSIX-specified  scheduling  policies
     above, Solaris also supports these scheduling policies:

     SCHEDIA     Threads are scheduled according to  the  Inter-
                  Active   Class  (IA)  policy  as  described  in
                  priocntl(2).


     SCHEDFS    Threads are scheduled according  to  the  Fair-
                  Share   Class  (FS)  policy  as  described  in
                  priocntl(2).


     SCHEDFX     Threads are scheduled according to  the  Fixed-
                  Priority  Class  (FX)  policy  as  described in
                  priocntl(2).


  Solaris Threads
     Only scheduling policy supported is  SCHEDOTHER,  which  is
     timesharing, based on the TS scheduling class.

ERORS
     In a multithreaded application, EINTR can be  returned  from
     blocking system calls when another thread calls  forkall(2).

USAGE
  -mt compiler option
     The -mt compiler option compiles and links for multithreaded
     code.  It  compiles  source files with -DRENTRANT and aug-
     ments the set of support libraries properly.

ATRIBUTES
     See attributes(5) for descriptions of the  following  attri-
     butes:







SunOS 5.11          Last change: 11 Nov 2008                    6






Standards, Environments, and Macros                    threads(5)



     
           ATRIBUTE TYPE               ATRIBUTE VALUE       
    
     MT-Level                     MT-Safe, Fork 1-Safe        
    


SEE ALSO
     crle(1),     fork(2),     priocntl(2),     libpthread(3LIB),
     librt(3LIB),       libthread(3LIB),      pthreadatfork(3C),
     pthreadcreate(3C), attributes(5), standards(5)


     Linker and Libraries Guide









































SunOS 5.11          Last change: 11 Nov 2008                    7



OpenSolaris man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™