pthreads

PTHREADS(7)                Linux Programmer's Manual               PTHREADS(7)



åå
       pthreads - POSIX ã¹ã¬ãã

説æ
       POSIX.1 ã¯ãä¸è¬ã« POSIX ã¹ã¬ããã Pthreads ã¨ãã¦ç¥ããã ã¹ã¬ããã»ãã‐
       ã°ã©ãã³ã°ã®ã¤ã³ã¿ãã§ã¼ã¹ç¾¤ (é¢æ°ãããããã¡ã¤ã«)  ãè¦å®ãã¦ãããä¸ã¤ã®ãã‐
       ã»ã¹ã¯è¤æ°ã®ã¹ã¬ãããæã¤ãã¨ãã§ãã å¨ã¦ã®ã¹ã¬ããã¯åãããã°ã©ã ãå®è¡ããã
       ãããã®ã¹ã¬ããã¯åã大åã¡ã¢ãª (ãã¼ã¿ã¨ãã¼ãé å) ãå±æãããã
       åã¹ã¬ããã¯èªåå°ç¨ã®ã¹ã¿ã㯠(èªåå¤æ°) ãæã¤ã

       POSIX.1 ã¯ã¹ã¬ããéã§ã©ã®ãããªå±æ§ãå±æãããã«ã¤ãã¦ãå®ãã¦ãã
       (ã¤ã¾ãããããã®å±æ§ã¯ã¹ã¬ããåä½ã§ã¯ãªãããã»ã¹å¨ä½ã§å±éã§ãã):

       -  ããã»ã¹ ID

       -  親ããã»ã¹ ID

       -  ããã»ã¹ã°ã«ã¼ã ID ã¨ã»ãã·ã§ã³ ID

       -  å¶å¾¡ç«¯æ«

       -  ã¦ã¼ã¶ ID ã¨ã°ã«ã¼ã ID

       -  ãªã¼ãã³ãããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿

       -  ã¬ã³ã¼ãã®ãã㯠(fcntl(3)  åç§)

       -  ã·ã°ãã«ã®éç½®

       -  ãã¡ã¤ã«ã¢ã¼ãä½æãã¹ã¯ (umask(2))

       -  ã«ã¬ã³ãã»ãã£ã¬ã¯ã㪠(chdir(2))  ã¨ã«ã¼ãã»ãã£ã¬ã¯ã㪠(chroot(2))

       -  ã¤ã³ã¿ã¼ãã«ã»ã¿ã¤ã (setitimer(2))  㨠POSIX ã¿ã¤ã (timer_create(2))

       -  nice å¤ (setpriority(2))

       -  ãªã½ã¼ã¹å¶é (setrlimit(2))

       -  CPU æé (times(2))  ã¨ãªã½ã¼ã¹ (getrusage(2))  ã®æ¶è²»ç¶æ³ã®è¨æ¸¬

       ã¹ã¿ãã¯ã«ã¤ãã¦ããPOSIX.1 ã¯ã©ã®ãããªå±æ§ã
       åãã®ã¹ã¬ããã§ç¬ç«ã«ç®¡çãããããè¦å®ãã¦ãã:

       -  ã¹ã¬ãã ID (pthread_t ãã¼ã¿å)

       -  ã·ã°ãã«ãã¹ã¯ (pthread_sigmask(3))

       -  errno å¤æ°

       -  代æ¿ã·ã°ãã«ã¹ã¿ã㯠(sigaltstack(2))

       -  ãªã¢ã«ã¿ã¤ã ã»ã¹ã±ã¸ã¥ã¼ãªã³ã°ã®ããªã·ã¼ã¨åªå度
          (sched_setscheduler(2)  㨠sched_setparam(2))

       以ä¸ã® Linux ç¹æã®æ©è½ãã¹ã¬ããåä½ã§ãã:

       -  ã±ã¼ãããªã㣠(capabilities(7)  åç§)

       -  CPU affinity (親å度)  (sched_setaffinity(2))

   pthreads é¢æ°ã®è¿ãå¤
       ã»ã¨ãã©ã® pthreads é¢æ°ã¯æåãã㨠0 ãè¿ãã 失æããå ´åã¨ã©ã¼çªå·ãè¿ãã
       pthreads é¢æ°ã¯ errno ãã»ããããªãç¹ã«æ³¨æãããã¨ã POSIX.1-2001 ã§ã¯ã
       ã¨ã©ã¼ãè¿ãå¯è½æ§ã®ãã pthreads é¢æ°ãã¨ã©ã¼ EINTR
       ã§å¤±æãããã¨ã¯æ±ºãã¦ãªãã¨è¦å®ãã¦ããã

   ã¹ã¬ãã ID
       ããããã»ã¹åã®åã¹ã¬ãã㯠(pthread_t åã®) ä¸æãªã¹ã¬ããèå¥åãæã¤ã ãã®èå¥åã¯ã
       pthread_create(3) ã®å¼ã³åºãåã«è¿ããããã¾ããã¹ã¬ããã¯èªèº«ã®ã¹ã¬ããèå¥åã
       pthread_self(3)  ã使ã£ã¦åå¾ã§ããã ã¹ã¬ãã ID
       ã®ä¸ææ§ãä¿è¨¼ãããã®ã¯ãä¸ã¤ã®ããã»ã¹åã«ããã¦ã®ã¿ã§ããã çµäºããã¹ã¬ããã join
       ãããå¾ã§ã¯ãã¹ã¬ãã ID ã¯åå©ç¨ãããå¯è½æ§ãããã ã¹ã¬ãã ID
       ãå¼ãæ°ã«åãå¨ã¦ã®ã¹ã¬ããé¢æ°ã«ããã¦ã ãã® ID ã¯å¼ã³åºãåã¨åããã‐
       ã»ã¹åã®ä¸ã¤ã®ã¹ã¬ãããåç§ããã

   ã¹ã¬ããã»ã¼ããªé¢æ°
       ã¹ã¬ããã»ã¼ããªé¢æ°ã¯ãè¤æ°ã®ã¹ã¬ããããåæã«å¼ã³åºãã¦ãå®å¨ãª
       (ããªãã¡ãåæã«å¼ã³åºããããã«é¢ããããåãçµæãè¿ã) é¢æ°ã®ãã¨ã§ããã

       POSIX.1-2001 㨠POSIX.1-2008ã§ã¯ãä¸é¨ã®ä¾å¤ãé¤ãã
       æ¨æºã§è¦å®ããã¦ããå¨ã¦ã®é¢æ°ãã¹ã¬ããã»ã¼ãã§ãããã¨ãè¦æ±ãã¦ããã
       以ä¸ã®é¢æ°ãä¾å¤ã§ããã

           asctime()
           basename()
           catgets()
           crypt()
           ctermid() (NULL ã§ãªãå¼ãæ°ã渡ãããå ´å)
           ctime()
           dbm_clearerr()
           dbm_close()
           dbm_delete()
           dbm_error()
           dbm_fetch()
           dbm_firstkey()
           dbm_nextkey()
           dbm_open()
           dbm_store()
           dirname()
           dlerror()
           drand48()
           ecvt() [POSIX.1-2001 ã®ã¿ (POSIX.1-2008 ã§åé¤ããã)]
           encrypt()
           endgrent()
           endpwent()
           endutxent()
           fcvt() [POSIX.1-2001 ã®ã¿ (POSIX.1-2008 ã§åé¤ããã)]
           ftw()
           gcvt() [POSIX.1-2001 ã®ã¿ (POSIX.1-2008 ã§åé¤ããã)]
           getc_unlocked()
           getchar_unlocked()
           getdate()
           getenv()
           getgrent()
           getgrgid()
           getgrnam()
           gethostbyaddr() [POSIX.1-2001 ã®ã¿ (POSIX.1-2008 ã§åé¤ããã)]
           gethostbyname() [POSIX.1-2001 ã®ã¿ (POSIX.1-2008 ã§åé¤ããã)]
           gethostent()
           getlogin()
           getnetbyaddr()
           getnetbyname()
           getnetent()
           getopt()
           getprotobyname()
           getprotobynumber()
           getprotoent()
           getpwent()
           getpwnam()
           getpwuid()
           getservbyname()
           getservbyport()
           getservent()
           getutxent()
           getutxid()
           getutxline()
           gmtime()
           hcreate()
           hdestroy()
           hsearch()
           inet_ntoa()
           l64a()
           lgamma()
           lgammaf()
           lgammal()
           localeconv()
           localtime()
           lrand48()
           mrand48()
           nftw()
           nl_langinfo()
           ptsname()
           putc_unlocked()
           putchar_unlocked()
           putenv()
           pututxline()
           rand()
           readdir()
           setenv()
           setgrent()
           setkey()
           setpwent()
           setutxent()
           strerror()
           strsignal() [POSIX.1-2008 ã§è¿½å ããã]
           strtok()
           system() [POSIX.1-2008 ã§è¿½å ããã]
           tmpnam() (NULL ã§ãªãå¼ãæ°ã渡ãããå ´å)
           ttyname()
           unsetenv()
           wcrtomb() (æå¾ã®å¼ãæ°ã NULL ã®å ´å)
           wcsrtombs() (æå¾ã®å¼ãæ°ã NULL ã®å ´å)
           wcstombs()
           wctomb()

   async-cancel-safe é¢æ°
       async-cancel-safe é¢æ°ã¯ã éåæã‐
       ã£ã³ã»ã«æ©è½ãæå¹ã«ãªã£ã¦ããã¢ããªã±ã¼ã·ã§ã³ã§
       å®å¨ã«å¼ã³åºããã¨ãã§ããé¢æ°ã®ãã¨ã§ãã (pthread_setcancelstate(3) ãåç§)ã

       以ä¸ã®é¢æ°ã ãããPOSIX.1-2001 㨠POSIX.1-2008 㧠async-cancel-safe ã§
       ãªããã°ãªããªãã¨ããã¦ããã

           pthread_cancel()
           pthread_setcancelstate()
           pthread_setcanceltype()

   åãæ¶ããã¤ã³ã (cancellation points)
       POSIX.1 ã®è¦å®ã§ã¯ãç¹å®ã®é¢æ°ã¯åãæ¶ããã¤ã³ãã§ãªããã°ãªããã
       ä»ã®ç¹å®ã®é¢æ°ã¯åãæ¶ããã¤ã³ãã§ãã£ã¦ãããã¨ããã¦ããã
       ããã¹ã¬ãããåãæ¶ãå¯è½ã§ããã®åãæ¶ãç¨®å¥ (cancelability type)  ã延æ
       (deferred) ã§ããã®ã¹ã¬ããã«å¯¾ããåãæ¶ãè¦æ±ãå¦çå¾ã¡ã®å ´åã
       åãæ¶ããã¤ã³ãã§ããé¢æ°ãå¼ã³åºããæç¹ã§ããã®ã¹ã¬ããã®ãã£ã³ã»ã«ã è¡ãããã

       POSIX.1-2001 㨠POSIX.1-2008 ã®ä¸¡æ¹ããããã¯ããããä¸æ¹ã§ã¯ã
       以ä¸ã®é¢æ°ã¯ãåãæ¶ããã¤ã³ã (cancellation points) ã§
       ãããã¨ãå¿é ã¨ãªã£ã¦ããã

           accept()
           aio_suspend()
           clock_nanosleep()
           close()
           connect()
           creat()
           fcntl() F_SETLKW
           fdatasync()
           fsync()
           getmsg()
           getpmsg()
           lockf() F_LOCK
           mq_receive()
           mq_send()
           mq_timedreceive()
           mq_timedsend()
           msgrcv()
           msgsnd()
           msync()
           nanosleep()
           open()
           openat() [POSIX.1-2008 ã§è¿½å ããã]
           pause()
           poll()
           pread()
           pselect()
           pthread_cond_timedwait()
           pthread_cond_wait()
           pthread_join()
           pthread_testcancel()
           putmsg()
           putpmsg()
           pwrite()
           read()
           readv()
           recv()
           recvfrom()
           recvmsg()
           select()
           sem_timedwait()
           sem_wait()
           send()
           sendmsg()
           sendto()
           sigpause() [POSIX.1-2001 only (moves to "may" list in POSIX.1-2008)]
           sigsuspend()
           sigtimedwait()
           sigwait()
           sigwaitinfo()
           sleep()
           system()
           tcdrain()
           usleep() [POSIX.1-2001 ã®ã¿ (POSIX.1-2008 ã§åé¤ããã)]
           wait()
           waitid()
           waitpid()
           write()
           writev()

       POSIX.1-2001 㨠POSIX.1-2008 ã®ä¸¡æ¹ããããã¯ããããä¸æ¹ã§ã¯ã
       以ä¸ã®é¢æ°ã¯ãåãæ¶ããã¤ã³ã (cancellation points) ã§
       ãã£ã¦ããããã¨ã«ãªã£ã¦ããã

           access()
           asctime()
           asctime_r()
           catclose()
           catgets()
           catopen()
           chmod() [POSIX.1-2008 ã§è¿½å ããã]
           chown() [POSIX.1-2008 ã§è¿½å ããã]
           closedir()
           closelog()
           ctermid()
           ctime()
           ctime_r()
           dbm_close()
           dbm_delete()
           dbm_fetch()
           dbm_nextkey()
           dbm_open()
           dbm_store()
           dlclose()
           dlopen()
           dprintf() [POSIX.1-2008 ã§è¿½å ããã]
           endgrent()
           endhostent()
           endnetent()
           endprotoent()
           endpwent()
           endservent()
           endutxent()
           faccessat() [POSIX.1-2008 ã§è¿½å ããã]
           fchmod() [POSIX.1-2008 ã§è¿½å ããã]
           fchmodat() [POSIX.1-2008 ã§è¿½å ããã]
           fchown() [POSIX.1-2008 ã§è¿½å ããã]
           fchownat() [POSIX.1-2008 ã§è¿½å ããã]
           fclose()
           fcntl() (cmd å¼ãæ°ãä½ã§ãã£ã¦ã)
           fflush()
           fgetc()
           fgetpos()
           fgets()
           fgetwc()
           fgetws()
           fmtmsg()
           fopen()
           fpathconf()
           fprintf()
           fputc()
           fputs()
           fputwc()
           fputws()
           fread()
           freopen()
           fscanf()
           fseek()
           fseeko()
           fsetpos()
           fstat()
           fstatat() [POSIX.1-2008 ã§è¿½å ããã]
           ftell()
           ftello()
           ftw()
           futimens() [POSIX.1-2008 ã§è¿½å ããã]
           fwprintf()
           fwrite()
           fwscanf()
           getaddrinfo()
           getc()
           getc_unlocked()
           getchar()
           getchar_unlocked()
           getcwd()
           getdate()
           getdelim() [POSIX.1-2008 ã§è¿½å ããã]
           getgrent()
           getgrgid()
           getgrgid_r()
           getgrnam()
           getgrnam_r()
           gethostbyaddr() [SUSv3 ã®ã¿ (ãã®é¢æ°ã¯ POSIX.1-2008 ã§åé¤ããã¦ãã)]
           gethostbyname() [SUSv3 ã®ã¿ (ãã®é¢æ°ã¯ POSIX.1-2008 ã§åé¤ããã¦ãã)]
           gethostent()
           gethostid()
           gethostname()
           getline() [POSIX.1-2008 ã§è¿½å ããã]
           getlogin()
           getlogin_r()
           getnameinfo()
           getnetbyaddr()
           getnetbyname()
           getnetent()
           getopt() (opterr ã 0 以å¤ã®å ´å)
           getprotobyname()
           getprotobynumber()
           getprotoent()
           getpwent()
           getpwnam()
           getpwnam_r()
           getpwuid()
           getpwuid_r()
           gets()
           getservbyname()
           getservbyport()
           getservent()
           getutxent()
           getutxid()
           getutxline()
           getwc()
           getwchar()
           getwd() [SUSv3 ã®ã¿ (ãã®é¢æ°ã¯ POSIX.1-2008 ã§åé¤ããã¦ãã)]
           glob()
           iconv_close()
           iconv_open()
           ioctl()
           link()
           linkat() [POSIX.1-2008 ã§è¿½å ããã]
           lio_listio() [POSIX.1-2008 ã§è¿½å ããã]
           localtime()
           localtime_r()
           lockf() [POSIX.1-2008 ã§è¿½å ããã]
           lseek()
           lstat()
           mkdir() [POSIX.1-2008 ã§è¿½å ããã]
           mkdirat() [POSIX.1-2008 ã§è¿½å ããã]
           mkdtemp() [POSIX.1-2008 ã§è¿½å ããã]
           mkfifo() [POSIX.1-2008 ã§è¿½å ããã]
           mkfifoat() [POSIX.1-2008 ã§è¿½å ããã]
           mknod() [POSIX.1-2008 ã§è¿½å ããã]
           mknodat() [POSIX.1-2008 ã§è¿½å ããã]
           mkstemp()
           mktime()
           nftw()
           opendir()
           openlog()
           pathconf()
           pclose()
           perror()
           popen()
           posix_fadvise()
           posix_fallocate()
           posix_madvise()
           posix_openpt()
           posix_spawn()
           posix_spawnp()
           posix_trace_clear()
           posix_trace_close()
           posix_trace_create()
           posix_trace_create_withlog()
           posix_trace_eventtypelist_getnext_id()
           posix_trace_eventtypelist_rewind()
           posix_trace_flush()
           posix_trace_get_attr()
           posix_trace_get_filter()
           posix_trace_get_status()
           posix_trace_getnext_event()
           posix_trace_open()
           posix_trace_rewind()
           posix_trace_set_filter()
           posix_trace_shutdown()
           posix_trace_timedgetnext_event()
           posix_typed_mem_open()
           printf()
           psiginfo() [POSIX.1-2008 ã§è¿½å ããã]
           psignal() [POSIX.1-2008 ã§è¿½å ããã]
           pthread_rwlock_rdlock()
           pthread_rwlock_timedrdlock()
           pthread_rwlock_timedwrlock()
           pthread_rwlock_wrlock()
           putc()
           putc_unlocked()
           putchar()
           putchar_unlocked()
           puts()
           pututxline()
           putwc()
           putwchar()
           readdir()
           readdir_r()
           readlink() [POSIX.1-2008 ã§è¿½å ããã]
           readlinkat() [POSIX.1-2008 ã§è¿½å ããã]
           remove()
           rename()
           renameat() [POSIX.1-2008 ã§è¿½å ããã]
           rewind()
           rewinddir()
           scandir() [POSIX.1-2008 ã§è¿½å ããã]
           scanf()
           seekdir()
           semop()
           setgrent()
           sethostent()
           setnetent()
           setprotoent()
           setpwent()
           setservent()
           setutxent()
           sigpause() [POSIX.1-2008 ã§è¿½å ããã]
           stat()
           strerror()
           strerror_r()
           strftime()
           symlink()
           symlinkat() [POSIX.1-2008 ã§è¿½å ããã]
           sync()
           syslog()
           tmpfile()
           tmpnam()
           ttyname()
           ttyname_r()
           tzset()
           ungetc()
           ungetwc()
           unlink()
           unlinkat() [POSIX.1-2008 ã§è¿½å ããã]
           utime() [POSIX.1-2008 ã§è¿½å ããã]
           utimensat() [POSIX.1-2008 ã§è¿½å ããã]
           utimes() [POSIX.1-2008 ã§è¿½å ããã]
           vdprintf() [POSIX.1-2008 ã§è¿½å ããã]
           vfprintf()
           vfwprintf()
           vprintf()
           vwprintf()
           wcsftime()
           wordexp()
           wprintf()
           wscanf()

       å®è£æã«ãæ¨æºè¦æ ¼ã§è¦å®ããã¦ããªããã®ä»ã®é¢æ°ãåãæ¶ããã¤ã³ã
       ã¨ãããã¨ãèªãããã¦ããã ç¹ã«ãåæ¢ (block)
       ããå¯è½æ§ãããéæ¨æºã®é¢æ°ãåãæ¶ããã¤ã³ã㨠ããå®è£ã¯ããå¾ããã¨ã ãã
       (ãã¡ã¤ã«ãæ±ãå¯è½æ§ã®ããã»ã¨ãã©ã®é¢æ°ãããã«å«ã¾ãã)ã

   Linux ã§ã®ã³ã³ãã¤ã«
       Linux ã§ã¯ãPthreads API ãç¨ããããã°ã©ã 㯠cc -pthread
       ã§ã³ã³ãã¤ã«ãã¹ãã§ããã

   POSIX ã¹ã¬ããã® Linux ã§ã®å®è£
       ããã¾ã§ã2ã¤ã®ã¹ã¬ããã®å®è£ã Linux ã® GNU C ã©ã¤ãã©ãªã«ãã æä¾ããã¦ããã

       LinuxThreads
              æåã® Pthreads ã®å®è£ã glibc 2.4
              以éã¯ããã®å®è£ã¯ãã¯ããµãã¼ãããã¦ããªãã

       NPTL (Native POSIX Threads Library)
              æ°ãã Pthreads ã®å®è£ãLinuxThreads ã¨æ¯ã¹ãã¨ã NPTL 㯠POSIX.1
              ã®è¦æ±ä»æ§ã¸ã®æºæ ã®åº¦åããé«ãã å¤æ°ã®ã¹ã¬ãããä½æããéã®æ§è½ãé«ãã
              NPTL 㯠glibc 2.3.2 以éã§å©ç¨å¯è½ã§ããã NPTL ãå©ç¨ããã«ã¯ Linux
              2.6 ã«ã¼ãã«ã«å®è£ããã¦ããæ©è½ãå¿è¦ã§ããã

       ã©ã¡ãã®å®è£ããããã 1:1 å®è£ãããªãã¡åãã®ã¹ã¬ããã
       ã«ã¼ãã«ã®ã¹ã±ã¸ã¥ã¼ãªã³ã°å®ä½ã«ãããã³ã°ãããã ã©ã¡ãã®ã¹ã¬ããã®å®è£ã Linux
       ã® clone(2)  ã·ã¹ãã ã³ã¼ã«ãå©ç¨ãã¦ããã NPTL ã§ã¯ãã¹ã¬ããåæã®åºæ¬æ©æ§
       (mutex ã ã¹ã¬ããã® join ç) 㯠Linux ã® futex(2)
       ã·ã¹ãã ã³ã¼ã«ã使ã£ã¦å®è£ããã¦ããã

   LinuxThreads
       ãã®å®è£ã®å¤§ããªç¹å¾´ã¯ä»¥ä¸ã®éãã§ãã:

       -  ã¡ã¤ã³ã¹ã¬ãã (æåã®ã¹ã¬ãã) ã¨ããã°ã©ã ã pthread_create(3)
          ã使ã£ã¦ä½æããã¹ã¬ããã«å ãã ãã®å®è£ã§ã¯ã管ç (manager)ãã¹ã¬ãããä½æãããã
          管çã¹ã¬ããã¯ã¹ã¬ããã®ä½æã¨çµäºãåãæ±ã (ãã®ã¹ã¬ããããã£ãã kill
          ãããã¨ãåé¡ãèµ·ãããã¨ããã)ã

       -  ãã®å®è£ã§ã¯åé¨ã§ã·ã°ãã«ã使ç¨ãã¦ããã Linux 2.2
          以éã§ã¯ããªã¢ã«ã¿ã¤ã ã·ã°ãã«ã®ãã¡æåã® 3ã¤ã使ããã (signal(7) åç§)ã
          ãã以åã®ã«ã¼ãã«ã§ã¯ SIGUSR1 㨠SIGUSR2 ã使ãããã
          ã¢ããªã±ã¼ã·ã§ã³ã¯ãã¹ã¬ããå®è£ã§å©ç¨ããã¦ããã·ã°ãã«ã
          ã©ãã使ããªãããã«ããªããã°ãªããªãã

       -  ã¹ã¬ããéã§ããã»ã¹ ID ãå±æããªã (å®éã«ã¯ LinuxThreads
          ã®ã¹ã¬ããã¯é常ããã¯æå ±ãå±æããããã»ã¹ã¨ã㦠å®è£ããã¦ããããä¸ã¤ã®å±éã®ãã‐
          ã»ã¹ ID ãå±æãã¦ã¯ããªã)ã (管çã¹ã¬ãããå«ã) LinuxThreads ã¹ã¬ãã㯠ps(1)
          ã使ãã¨å¥ã®ããã»ã¹ã®ããã«è¦ããã

       LinuxThreads ã®å®è£ã§ã¯ POSIX.1 ä»æ§ããé¸è±ãã¦ããç¹ã
       ããã¤ãããã以ä¸ã«ç¤ºããããªç¹ããã:

       -  getpid(2)  ãå¼ã³åºããã¨ãã«ãã¹ã¬ããæ¯ã«ç°ãªãå¤ãè¿ãããã

       -  ã¡ã¤ã³ã¹ã¬ãã以å¤ã®ã¹ã¬ãã㧠getppid(2)  ãå¼ã³åºãã¨ã管çã¹ã¬ããã®ãã‐
          ã»ã¹ ID ãè¿ãããã æ¬å½ã¯ããããã®ã¹ã¬ãã㧠getppid(2)
          ãå¼ãã å ´åã«ã¯ã¡ã¤ã³ã¹ã¬ããã§ã® getppid(2)  ã¨åãå¤ãè¿ãã¹ãã§ããã

       -  ããã¹ã¬ããã fork(2)  ã使ã£ã¦æ°ããåããã»ã¹ãä½æããå ´åã ã©ã®ã¹ã¬ããã§ããã®å‐
          ããã»ã¹ã wait(2) ã§ããã¹ãã§ãããããããªããããã®å®è£ã§ã¯åããã»ã¹ãä½æãã
          ã¹ã¬ããã ãããã®åããã»ã¹ã wait(2)  ã§ããã

       -  ããã¹ã¬ããã execve(2)  ãå¼ã³åºããå ´åãä»ã®ã¹ã¬ããã¯å¨ã¦çµäºããã (POSIX.1
          ã®ä»æ§éã)ã ããããªãããæ°ããããã»ã¹ã¯ execve(2)  ãå¼ãã ã¹ã¬ããã¨åã PID
          ãæã¤ãæ£ãã㯠ã¡ã¤ã³ã¹ã¬ããã¨åã PID ãæã¤ã¹ãã§ããã

       -  ã¹ã¬ããéã§ã¦ã¼ã¶ ID ã¨ã°ã«ã¼ã ID ãå±æãããªã ãã®ãã¨ã¯ãset-user-ID ãã‐
          ã°ã©ã ã§é¢åãªäºæãæãããã ã¢ããªã±ã¼ã·ã§ã³ã seteuid(2)
          ãªã©ã使ã£ã¦ä¿¡ç¨æå ± (credentials) ãå¤æ´ããå ´åã« Pthreads
          é¢æ°ã失æããåå ã¨ãªãã

       -  ã¹ã¬ããéã§å±éã®ã»ãã·ã§ã³ ID ãããã»ã¹ã°ã«ã¼ã ID ãå±æããªãã

       -  ã¹ã¬ããé㧠fcntl(2)  ã使ã£ã¦ä½æãããã¬ã³ã¼ãã»ããã¯ãå±æããªãã

       -  times(2)  㨠getrusage(2)  ãè¿ãæå ±ããã‐
          ã»ã¹å¨ä½ã®æå ±ã§ãªãã¹ã¬ããåä½ã®æå ±ã§ããã

       -  ã¹ã¬ããéã§ã»ããã©ã®ã¢ã³ãã¥å¤ (semop(2)  åç§) ãå±æããªãã

       -  ã¹ã¬ããéã§ã¤ã³ã¿ã¼ãã«ã»ã¿ã¤ããå±æããªãã

       -  ã¹ã¬ããã¯å±éã® nice å¤ãå±æããªãã

       -  POSXI.1 ã§ã¯ãå¨ä½ã¨ãã¦ã®ããã»ã¹ã«éãããã·ã°ãã«ã¨ã
          åå¥ã®ã¹ã¬ããã«éãããã·ã°ãã«ãåºå¥ãã¦èãã¦ããã POSIX.1 ã«ããã¨ããã‐
          ã»ã¹ã«éãããã·ã°ãã« (ä¾ãã° kill(2)  ã使ã£ã¦éã) ã¯ããã®ãã‐
          ã»ã¹ã«å±ãã¹ã¬ããã®ãã¡ åæã« (arbitrarily)
          ã«é¸æãããä¸ã¤ã®ã¹ã¬ããã«ããå¦çããã ãã¨ã«ãªã£ã¦ãããLinuxThreads ã¯ãã‐
          ã»ã¹ã«éãããã·ã°ãã«ã®
          æ¦å¿µã«å¯¾å¿ãã¦ããããã·ã°ãã«ã¯ç¹å®ã®ã¹ã¬ããã«ã ãéããã¨ãã§ããã

       -  ã¹ã¬ããã¯ããããã®ç¬èªã®ä»£æ¿ã·ã°ãã«ã¹ã¿ãã¯ã®è¨å®ãæã¤ã
          ããããæ°ããã¹ã¬ããã®ä»£æ¿ã·ã°ãã«ã¹ã¿ãã¯ã®è¨å®ã¯
          ãã®ã¹ã¬ãããä½æããã¹ã¬ããããã³ãã¼ããããã®ãã
          ã¹ã¬ããã¯æåã¯ä¸ã¤ã®ä»£æ¿ã·ã°ãã«ã¹ã¿ãã¯ãå±æããã
          (ä»æ§ã§ã¯ãæ°ããã¹ã¬ããã¯ä»£æ¿ã·ã°ãã«ã¹ã¿ãã¯ãå®ç¾©ããã¦ããªãç¶æ
          ã§éå§ãããã¹ãã¨ããã¦ããã
          2ã¤ã®ã¹ã¬ãããå±æããã¦ãã代æ¿ã·ã°ãã«ã¹ã¿ãã¯ä¸ã§åæã«
          ã·ã°ãã«ã®å¦çãè¡ã£ãå ´åãäºæ¸¬ä¸å¯è½ãªããã°ã©ã ã®ã¨ã©ã¼ã èµ·ããå¾ãã)

   NPTL
       NPTL ã§ã¯ãä¸ã¤ã®ããã»ã¹ã®å¨ã¦ã®ã¹ã¬ããã¯åãã¹ã¬ããã»ã°ã«ã¼ã ã«å±ãã;
       ã¹ã¬ããã»ã°ã«ã¼ãã®å¨ã¡ã³ãã¼ã¯åã PID ãå±æããã NPTL ã¯ç®¡çã¹ã¬ãã (manager
       thread) ãå©ç¨ããªãã NPTL ã¯åé¨ã§ãªã¢ã«ã¿ã¤ã ã·ã°ãã«ã®ãã¡æåã®
       2ã¤ã®çªå·ã使ç¨ãã¦ãã (signal(7)
       åç§)ããããã®ã·ã°ãã«ã¯ã¢ããªã±ã¼ã·ã§ã³ã§ã¯ä½¿ç¨ã§ããªãã

       NPTL ã«ã POSIX.1 ã«æºæ ãã¦ããªãç¹ãå°ãªãã¨ãä¸ã¤ãã:

       -  ã¹ã¬ããã¯å±éã® nice å¤ãå±æããªãã

       NPTL ã®æ¨æºéæºæ ãªç¹ã®ãã¡ããã¤ãã¯ä»¥åã®ã«ã¼ãã«ã§ã®ã¿çºçãã:

       -  times(2)  㨠getrusage(2)  ãè¿ãæå ±ããã‐
          ã»ã¹å¨ä½ã®æå ±ã§ãªãã¹ã¬ããåä½ã®æå ±ã§ãã (ã«ã¼ãã« 2.6.9 ã§ä¿®æ£ããã)ã

       -  ã¹ã¬ããéã§ãªã½ã¼ã¹å¶éãå±æããªã (ã«ã¼ãã« 2.6.10 ã§ä¿®æ£ããã)ã

       -  ã¹ã¬ããéã§ã¤ã³ã¿ã¼ãã«ã»ã¿ã¤ããå±æããªã (ã«ã¼ãã« 2.6.12 ã§ä¿®æ£ããã)ã

       -  ã¡ã¤ã³ã¹ã¬ããã ãã setsid(2)  ã使ã£ã¦æ°ããã»ãã·ã§ã³ãéå§ãããã¨ãã§ãã
          (ã«ã¼ãã« 2.6.16 ã§ä¿®æ£ããã)ã

       -  ã¡ã¤ã³ã¹ã¬ããã ãã setpgid(2)  ã使ã£ã¦ãã®ããã»ã¹ããã‐
          ã»ã¹ã»ã°ã«ã¼ãã»ãªã¼ãã¼ã«ãããã¨ãã§ãã (ã«ã¼ãã« 2.6.16 ã§ä¿®æ£ããã)ã

       -  ã¹ã¬ããã¯ããããã®ç¬èªã®ä»£æ¿ã·ã°ãã«ã¹ã¿ãã¯ã®è¨å®ãæã¤ã
          ããããæ°ããã¹ã¬ããã®ä»£æ¿ã·ã°ãã«ã¹ã¿ãã¯ã®è¨å®ã¯
          ãã®ã¹ã¬ãããä½æããã¹ã¬ããããã³ãã¼ããããã®ãã
          ã¹ã¬ããã¯æåã¯ä¸ã¤ã®ä»£æ¿ã·ã°ãã«ã¹ã¿ãã¯ãå±æãã (ã«ã¼ãã« 2.6.16 ã§ä¿®æ‐
          £ããã)ã

       NPTL ã®å®è£ã§ã¯ä»¥ä¸ã®ç¹ã«ã¤ãã¦ã注æãããã¨:

       -  ã¹ã¿ãã¯ãµã¤ãºã®ãªã½ã¼ã¹ã®ã½ããã»ãªããã (setrlimit(2)  ã® RLIMIT_STACK
          ã®èª¬æãåç§) ã unlimited 以å¤ã®å¤ã«è¨å®ããã¦ããå ´åãã½ããã»ãªãããã®å¤ã
          æ°ããã¹ã¬ããã®ããã©ã«ãã®ã¹ã¿ãã¯ãµã¤ãºã¨ãªãã è¨å®ãæå¹ã«ããããã«ã¯ããã‐
          ã°ã©ã ãå®è¡ããåã«ãªãããå¤ã è¨‐
          å®ãã¦ãããªããã°ãªããªããããã¦ãã¯ãã·ã§ã«ã®çµã¿è¾¼ã¿ã³ãã³ãã® ulimit -s (C
          ã·ã§ã«ã§ã¯ limit stacksize)  ã使ã£ã¦è¨å®ããã

   ã¹ã¬ããå®è£ã®å¤å®
       glibc 2.3.2 以éã§ã¯ã getconf(1)  ã³ãã³ãã使ã£ã¦ã
       ã·ã¹ãã ã®ã¹ã¬ããå®è£ãå¤å®ãããã¨ãã§ããã 以ä¸ã«ä¾ã示ã:

           bash$ getconf GNU_LIBPTHREAD_VERSION
           NPTL 2.3.4

       ãã以åã® glibc ã®ãã¼ã¸ã§ã³ã§ã¯ã以ä¸ã®ãããªã³ãã³ãã§
       ããã©ã«ãã®ã¹ã¬ããå®è£ãå¤å®ãããã¨ãã§ããã

           bash$ $( ldd /bin/ls | grep libc.so | awk '{print $3}' ) | \
                           egrep -i 'threads|ntpl'
                   Native POSIX Threads Library by Ulrich Drepper et al

   ã¹ã¬ããã®å®è£ã®é¸æ: LD_ASSUME_KERNEL
       LinuxThreads 㨠NPTL ã®ä¸¡æ¹ããµãã¼ããã¦ãã glibc (glibc 2.3.x)
       ãããã·ã¹ãã ã§ã¯ã LD_ASSUME_KERNEL ç°å¢å¤æ°ã使ããã¨ã§ãåçãªã³ã«ãããã©ã«ãã§
       é¸æããã¹ã¬ããå®è£ãä¸æ¸ããããã¨ãã§ããã
       ãã®å¤æ°ã«ãããåçãªã³ã«ãç¹å®ã®ãã¼ã¸ã§ã³ã®ã«ã¼ãã«ä¸ã§
       åä½ãã¦ããã¨ä»®å®ããããã«æå®ããã NPTL
       ãå¿è¦ã¨ãããµãã¼ãæ©è½ãæä¾ãã¦ããªãã«ã¼ãã«ãã¼ã¸ã§ã³ã æå®ãããã¨ã§ãå¼·å¶çã«
       LinuxThreads ã使ããã¨ãã§ãã (ãã®ãããªãã¨ãããæããããããªå ´é¢ã¯ã LinuxThreads
       ã®æ¨æºéæºæ ãªæ¯èãã«ä¾åãã (å£ãã) ã¢ããªã±ã¼ã·ã§ã³ ãåä½ãããå ´åã ãã)ã
       以ä¸ã«ä¾ã示ã:

           bash$ $( LD_ASSUME_KERNEL=2.2.5 ldd /bin/ls | grep libc.so | \
                           awk '{print $3}' ) | egrep -i 'threads|ntpl'
                   linuxthreads-0.10 by Xavier Leroy

é¢é£é ç®
       clone(2), futex(2), gettid(2), futex(7), sigevent(7), signal(7),

       pthreads ã®å種ããã¥ã¢ã«ãã¼ã¸ãä¾ãã°: pthread_attr_init(3),
       pthread_atfork(3), pthread_cancel(3), pthread_cleanup_push(3),
       pthread_cond_signal(3), pthread_cond_wait(3), pthread_create(3),
       pthread_detach(3), pthread_equal(3), pthread_exit(3),
       pthread_key_create(3), pthread_kill(3), pthread_mutex_lock(3),
       pthread_mutex_unlock(3), pthread_once(3), pthread_setcancelstate(3),
       pthread_setcanceltype(3), pthread_setspecific(3), pthread_sigmask(3),
       pthread_sigqueue(3), and pthread_testcancel(3)

ãã®ææ¸ã«ã¤ãã¦
       ãã® man ãã¼ã¸ã¯ Linux man-pages ããã¸ã§ã¯ãã®ãªãªã¼ã¹ 3.51 ã®ä¸é¨
       ã§ãããããã¸ã§ã¯ãã®èª¬æã¨ãã°å ±åã«é¢ããæå ±ã¯
       http://www.kernel.org/doc/man-pages/ ã«æ¸ããã¦ããã



Linux                             2010-11-14                       PTHREADS(7)