스레드(Threads)

Computer/OS | 2006/07/05 20:11 | adioshun
 

스레드(Threads)

5.1 개요

5.2 장점

5.3 사용자 및 커널 스레드(User and Kernel Threads)

5.4 다중 스레드 모델(Multithreading Models)

5.5 솔라리스(Solaris)2 스레드(threads)

5.6 Java 스레드(threads)

5.7 요약


5.1 개요

- 스레드(threads) : LWP( Light Weight Process)

- 전통적인 프로세스 : heavy Weight Process

- CPU이용의 기본 단위이다.

- 스레드는 스레드ID, 프로그램 카운터, 레지스터 집합, 스택으로 구성됨

- 같은 프로세스에 속한 다른 스레드와 코드, 데이터, 파일, 신호 등등의 운영체제 자원을 공유한다.

- 필요성 : 하나의 프로그램이 다양한 작업 실행을 요구 할때

       ex) word processor, web browser,      -> 다른 일

           web server,                      -> 같은 일

           RPC server, RMI server, kernel threads

           -> 해결책 : multiple process       -> 오버헤드가 크다

                       하나의 프로세스에 여러개 스레드 -> 효과적


5.2 장점(Benefits)

- 응답성(Responsiveness)

- 자원 공유(Resource Sharing)

- 경제성(Economy) - 스레드를 생성, Context Switching에서 Process복제보다 경제적

- 다중 처리기 구조의 활용(Utilization of multiprocessor architecture)

       # 다중 처리기 구조에서는 각각의 스레드가 병렬로 처리될수 있다.

       # 단일 처리기 구조에서는 병렬인것 같지만 실제로 한번에 하나의 스레드만 수행됨


5.3 사용자 및 커널 스레드(User and Kernel Thread)

- 스레드를 위한 지원은 사용자 스레드(user threads)를 위해서는 사용자 수준에서,

                   커널 스레드(kernel threads)를 위해서는 커널 수준에서 제공된다.


5.3.1 사용자 스레드(User Threads)

- 스레드 라이브러리에 의해 구현된다.

- 라이브러리는 커널의 지원 없이 유저 공간에서 스레드의 생성과, 스케줄링, 관리를 지원한다.

- 장점 : 생성과 관리가 빠르다.

- 단점 : 커널이 단일 스레드형 이라면 blocking system call을 수행하는 사용자 수준의 스레드는 다른 스레드가 있어도 프로세스 전체가 block된다.

- POSIX Pthreads, Java threads, Win32 threads


5.3.2 커널 스레드(Kernel Threads)

- 운영체제에 의해 직접 지원된다. (kernel이 지원해준다)

- 커널이 커널공간에서 스레드의 생성과, 스케줄링, 관리를 한다.

- 단점 : 생성과 관리가 느리다.

- 장점 : 스레드가 blocking system call을 수행하면 커널은 다른 스레드의 수행을 스케줄링 한다.

        다중처리기환경에서는 스레드를 서로 다른 처리기에서 스케줄 할 수 있다.

- Windows XP/2000, Solaris, Linux, Tru64 UNIX(formerly digital UNIX), Mac OS X


5.4 다중 스레드 모델(Multithreading Models)

- 많은 시스템은 사용자스레드(User Threads)와 커널스레드(Kernel Threads)를 모두 지원한다.

- 다중 스레드 모델의 종료 -> (user threads)-to-(kernel threads)

       # Many-to-One
     
# One-to-One

       
# Many-to-Many


5.4.1 Many-to-One 모델

- 많은 사용자 수준의 스레드를 하나의 커널 스레드로 맵한다.

- 장점 : 스레드관리는 사용자공간에서 행해진다. -> 효율적

- 단점 : 스레드가 blocking system call을 할 경우 전체가 block됨.

한번에 하나의 스레드만이 커널에 접근 -> 다중 스레드가 다중 처리기에서 작동 안됨.

- 커널스레드를 지원하지 않는 운영체제에서 사용된다.

- 커널은 스레드가 한 개인것 처럼 보임

- Solaris Green Threads, GNU Portable Thread


5.4.2 One-to-One 모델

- 사용자스레드를 각각 하나의 커널스레드에 맵한다.

- 장점 : 하나의 스레드가 blocking system call을 하더라도 다른 스레드가 작업 할 수 있다.

        다중 처리기에서 다중 스레드가 병렬로 수행되는 것을 허용함.

- 단점 : 사용자스레드를 생성할 때 마다 커널스레드를 생성해야한다. ->성능저하 => 스레드 수 제한시킴

- Windows NT/XP/2000, Linux, Solaris 9 and later



5.4.3 Many-to-Many 모델

- 여러 개의 사용자 수준 스레드를 그보다 작거나 같은 수의 커널 스레드로 다중화(multiplex)한다.

- 개발자는 플요한 만큼 많은 사용자스레드를 생성하면 상응하는 커널스레드가 다중 처리기에서 병렬로 수행.

- 스레드가 blocking system call을 해도 다른 스레드로 스케줄 함.

- Window NT/2000, Solaris, IRIX, Digital UNIX


5.4.4. Two-Level 모델

- Many-to-Many의 변형이다.

- 사용자스레드가 커널스레드에 바인드 되는 것을 허용한다.

- 바인드된 스레드 : 사용자수준 스레드와 커널 스레드가 붙어서 스케줄링 되지 않고 계속 연결되어 있는 것


5.4.5 Threading Issues

- multithreaded 프로그램에서 fork()와 exec()시스템콜의 의미?

- fork()2가지 버전

       # 모든 스레드 복제            -> fork - no exec

       # 호출한 스레드만 복제 -> fork - exec

- exec()

       단일 스레드 프로그램처럼 동작. -> 모든 스레드를 포함하는 프로세스로 대체 됨


5.4.6 Thread cancellation (스레드 해제(취소))

- 해제의 일반적인 목적 2가지

       # 비동기 해제 : 타겟 스레드를 즉시 종료시킴

       # 연기된 해제 : 타겟 스레드가 취소 되었는지 주기적으로 체크함

               -> cancellation point는 안전한 해제를 위함이다.


5.4.7 Thread Pools -> 버퍼와 비슷??

- Muntithreaded server의 잠재적인 문제점

       # 완료되면 버려질지도 모른다.

       # 제한이 없는 스레드는 시스템자원을 다 써버릴 수도 있다.

- Thread Pool

       # 프로세스가 시작하면 몇 개의 스레드를 pool에 만들어 놓는다.

       # 서버가 요청을 받으면 스레드를 풀에서 깨운다

- 이점

       # 요청을 받으면 새로 스레드를 만들 때 보다 약간 빠른 서비스를 해준다.

       # 프로그램에서 허락한 스레드의 개수로 pool의 크기가 정해진다.


5.4.8 Thread Specific Data (??)

- 몇몇 상화에, 각 스레드가 자신의 많은 데이터의 복제를 할 지도 모를때-> thread specific data

- 프로세스에 스레드가 너무 많이 생기는 것을 조절하는 것이 없을 때 유용함.(thread pool사용시)


5.4.9 Scheduler Activations (스케줄러 활동시작)

- Many-to-Many모델에서 사용자스레드와 커널스레드 사이의 중간에 위치한다.

- user thread ---- LWP ---- kernel thread

      M      :      1    :      1

- CPU bound 프로그램은 1개의 LWP로도 충분함

- I/O bound 프로그램은 여러개의 LWP가 필요

- 커널이 스레드가 블록되는 등의 이벤트가 있을때 프로그램에게 알려준다. ->upcall

- upcall은 스레드 라이브러리가 처리함



- LWP는 정확히 하나의 커널 스레드와 연결되어 있다.

- 커널 스레드는 LWP를 가지지 않고 동작하는 커널 스레드도 있다.(디스크요구서비스를 위한 스레드)



5.4 Pthreads

- POSIX의 스레드를 생성하고 동기화 하는 표준 API이다.

- Pthread library functions

       # pthread_create()

       # pthread_join() //스레드의 wait()같은것

       # pthread_exit()

       # pthread_attr_init()


5.5 Java Threads

- 언어 레벨에서 지원한다.

- 적어도 하나의 단일제어 스레드를 포함함

- 스레드생성

       1. Thread class 상속

       2. Runnable Interface 구현

- Java Thread States



참고 : Applied Operating System Concepts
작성 : satellite_k (http://blog.naver.com/satellite_k)
수정 : 2006.07.05 by 임헌정
http://www.4ellene.net
2006/07/05 20:11 2006/07/05 20:11
Trackback address :: http://4ellene.net/tt/trackback/953
  1. party poker

    Tracked from poker chips 2009/03/30 02:44  삭제

    free poker games

  2. Tracked from cruel rape 2009/04/13 16:19  삭제

    crime rape

  3. forced ass sex

    Tracked from forced bi 2009/04/14 13:25  삭제

    forced asian sex

  4. bdsm bondage

    Tracked from bdsm books 2009/04/15 07:29  삭제

    bdsm artwork

  5. rape dvd

    Tracked from brutal throat fuck 2009/06/29 06:04  삭제

    forced machine sex

  6. nude girl forced

    Tracked from forced sex scenes 2009/06/29 07:21  삭제

    forced mom sex

  7. extreme insertion anal

    Tracked from rape videos 2009/06/29 17:51  삭제

    rape videos

  8. daughter rape

    Tracked from extreme anal fucking 2009/06/29 22:24  삭제

    forced white wife

  9. hardcore rape porn

    Tracked from extreme board rape 2009/06/29 22:24  삭제

    rape pics

  10. lesbian rape porn

    Tracked from forced sex porn 2009/06/30 01:58  삭제

    rape porno

  11. extreme beast sex

    Tracked from rape fucking 2009/06/30 04:05  삭제

    gang rape pictures

  12. hentai rape porn

    Tracked from forced sex fantasy 2009/06/30 19:48  삭제

    forced sex movie

  13. forced lesbian sex

    Tracked from rape young 2009/06/30 21:38  삭제

    crime rape

  14. rape galleries

    Tracked from extreme fucking 2009/07/01 22:36  삭제

    torture rape

  15. forced anal sex

    Tracked from rape sex stories 2009/07/02 01:23  삭제

    rape anal

  16. rape videos

    Tracked from rape scene 2009/07/02 04:05  삭제

    porn hawaiian rape

  17. online casino slot

    Tracked from casino open usa 2009/07/10 02:37  삭제

    casino free online

  18. internet casino gambling

    Tracked from online casino game 2009/07/10 11:54  삭제

    tops casino

  19. free casinos online

    Tracked from online casinos no deposit 2009/07/10 19:55  삭제

    club usa casino bonus

  20. online no deposit casinos

    Tracked from online casinos in usa 2009/07/11 00:45  삭제

    free casino online

  21. free chip online casinos

    Tracked from casino website 2009/07/11 17:52  삭제

    new online casino

  22. top ten online casinos

    Tracked from free casinos online 2009/07/11 18:41  삭제

    online casino bonuses

  23. java internet casino

    Tracked from us online casino 2009/07/13 00:54  삭제

    american online casinos

  24. no deposit online casino

    Tracked from online free casino games 2009/07/13 10:36  삭제

    casino tour

  25. online casinos for american players

    Tracked from us friendly casinos 2009/07/13 15:24  삭제

    casino party usa

  26. casino guide http

    Tracked from online casinos accepting usa deposits 2009/07/14 03:30  삭제

    england casino

  27. tops casino

    Tracked from free casino online 2009/07/14 07:56  삭제

    play free casino games

  28. highest payouts online casino

    Tracked from free chip online casinos 2009/07/15 06:02  삭제

    online casino game

  29. online usa casinos

    Tracked from casino party usa 2009/07/15 07:58  삭제

    online no deposit casinos

  30. casino

    Tracked from directorio casino online 2009/07/15 17:03  삭제

    no bonus online casinos

  31. online casino sites

    Tracked from casino game online 2009/07/16 05:29  삭제

    free casinos online

  32. casino s online

    Tracked from australian online casino 2009/07/16 11:52  삭제

    online casino sites

  33. free online casinos

    Tracked from highest payouts online casino 2009/07/16 16:15  삭제

    free online casino slots

  34. casino gambling

    Tracked from casino wagering 2009/07/17 03:23  삭제

    top online casinos

  35. club usa casino bonus

    Tracked from online casino game 2009/07/17 05:21  삭제

    no deposit online casino

  36. casino betting

    Tracked from online casinos 2009/07/17 19:56  삭제

    online casinos for american players

  37. casino online games

    Tracked from free online casino 2009/07/18 02:49  삭제

    online casino site

  38. live online poker

    Tracked from casino gamble 2009/07/19 06:48  삭제

    online casino open to usa

  39. transvestite pics

    Tracked from shemale escorts 2009/07/20 05:17  삭제

    tranny tube

  40. mature tranny

    Tracked from shemale cumshot 2009/07/20 08:41  삭제

    tranny blowjob

  41. thai ladyboys

    Tracked from futanari toons 2009/07/20 10:51  삭제

    shemale pussy

  42. ladyboys in pantyhose

    Tracked from tranny threesome 2009/07/20 22:56  삭제

    hot transexuals

  43. tranny fuck

    Tracked from shemale porn 2009/07/21 02:45  삭제

    pictures of transexual woman

  44. transexual orgy

    Tracked from ladyboys in pantyhose 2009/07/21 15:23  삭제

    post op ladyboy

  45. ladyboy photos

    Tracked from transexual domination 2009/07/22 00:56  삭제

    young ladyboy

  46. transsexual services

    Tracked from transexual women 2009/07/22 16:23  삭제

    transgender personals

  47. shemale tube

    Tracked from hot shemales 2009/07/22 17:01  삭제

    sexy shemale

  48. transvestite in public

    Tracked from shemale pictures 2009/07/22 23:10  삭제

    transvestite cock

  49. transvestite sex

    Tracked from ladyboy dicks 2009/07/23 03:32  삭제

    wild tranny sex

  50. futanari video

    Tracked from transexual vanilla 2009/07/23 06:29  삭제

    transvestite porn

  51. transexual dating

    Tracked from transvestite photos 2009/07/23 12:12  삭제

    transvestite pictures

  52. asian ladyboy movies

    Tracked from ladyboy stories 2009/07/23 20:20  삭제

    transexual chat

  53. huge shemale

    Tracked from sexy transvestites 2009/07/23 23:21  삭제

    sexy transexuals

  54. transexual kissing

    Tracked from asian ladyboy movies 2009/07/23 23:31  삭제

    futanari girls

  55. tranny

    Tracked from shemale cock 2009/07/24 03:40  삭제

    shemale cumshot

  56. futanari fiction

    Tracked from tranny vids 2009/07/24 07:48  삭제

    transvestite porn

  57. ladyboy anal

    Tracked from lesbian tranny 2009/07/24 16:14  삭제

    ladyboy sex

  58. shemale fucking girl

    Tracked from young tranny 2009/07/25 03:27  삭제

    transexual galleries

  59. 3d incest

    Tracked from family sex 2009/09/06 03:24  삭제

    adult taboo stories

  60. Mother Sucks Son

    Tracked from Mother Son Porn 2009/09/06 04:47  삭제

    mother son sex

  61. fathers fucking daughters

    Tracked from dad fucking virgin daughter 2009/09/06 05:48  삭제

    father fucks daughter

  62. mom and daughter

    Tracked from mother daughter fuck 2009/09/06 11:34  삭제

    mom licks daughter

  63. Daughter Incest Incest

    Tracked from Incest Porn 2009/09/06 12:14  삭제

    Cartoon Incest

  64. brother sister incest

    Tracked from lesbian incest 2009/09/07 04:32  삭제

    family sex

  65. mom and son sex galleries

    Tracked from mom and son sex 2009/09/07 04:39  삭제

    mom daughter sex

  66. mom and daughter sex

    Tracked from mom daughter 2009/09/07 09:05  삭제

    incest lesbian stories

  67. incest mother and daughter

    Tracked from incest forum 2009/09/07 21:29  삭제

    incest pictures

  68. mom son fucking

    Tracked from mom mature son gallery 2009/09/08 04:55  삭제

    mom son sex

  69. daddies fucking daughters

    Tracked from daughter sex 2009/09/08 13:45  삭제

    dad and daughter incest

  70. daddy and little girl fantasy

    Tracked from daddies fucking daughters 2009/09/08 14:06  삭제

    daddy fuck me

  71. daughter sex

    Tracked from father daughter sex 2009/09/08 20:44  삭제

    daddies fucking daughters

  72. incest mother and daughter

    Tracked from incest forum 2009/09/08 22:23  삭제

    incest pictures

  73. dad and daughter

    Tracked from dad with sis son sex mom 2009/09/09 00:22  삭제

    dad fucking virgin daughter

  74. anime incest

    Tracked from amateur incest family porn 2009/09/09 13:41  삭제

    incest stories

  75. mom and daughter son

    Tracked from mom and daughter 2009/09/09 21:22  삭제

    mom and son sex

  76. daughter sex

    Tracked from daughter nude 2009/09/09 22:24  삭제

    family fucking

  77. bdsm sex movies

    Tracked from bdsm sex 2009/09/11 04:54  삭제

    bdsm slave

  78. girl bondage

    Tracked from genital torture 2009/09/12 04:44  삭제

    girls in bondage

  79. corset torture story

    Tracked from cock torture 2009/09/12 06:54  삭제

    device bondage

  80. vintage bondage

    Tracked from vaginal torture 2009/09/12 11:49  삭제

    water bondage

  81. self bondage

    Tracked from secretary bondage 2009/09/12 22:14  삭제

    sex bondage

  82. self bondage stories

    Tracked from self bondage 2009/09/13 01:36  삭제

    sex bondage

  83. orgasm torture

    Tracked from nipple torture 2009/09/13 07:00  삭제

    outdoor bdsm

  84. slave torture stories

    Tracked from slave girl 2009/09/13 21:45  삭제

    slave training

  85. self bondage stories

    Tracked from self bondage 2009/09/14 00:51  삭제

    sex bondage

  86. cock and ball torture

    Tracked from clit torture 2009/09/15 11:00  삭제

    cock ball torture

  87. bondage fix

    Tracked from bondage fairies 2009/09/15 18:36  삭제

    bondage fucking

  88. bondage rape

    Tracked from bondage porn 2009/09/16 07:24  삭제

    bondage sex

  89. bondage art

    Tracked from bondage anime 2009/09/16 11:20  삭제

    bondage blowjob

  90. incest cartoon

    Tracked from incest art 2009/09/28 09:28  삭제

    incest comics

  91. mother son sex

    Tracked from mother son porn 2009/09/29 13:00  삭제

    mother sucks son

  92. incest porn stories

    Tracked from porn incest 2009/09/29 17:01  삭제

    young incest porn

  93. daughter fucking incest porn

    Tracked from free incest porn stories 2009/10/01 20:14  삭제

    porn incest

  94. daughter incest incest

    Tracked from dad and daughter sex 2009/10/02 08:19  삭제

    dad daughter nude sex

  95. dad fucking virgin daughter

    Tracked from dad and daughter 2009/10/02 21:59  삭제

    fathers fucking daughters

  96. Cartoon Incest

    Tracked from free incest stories 2009/10/03 05:35  삭제

    Daughter Incest

  97. free incest pics

    Tracked from fathers fucking daughters 2009/10/03 06:49  삭제

    free mom and son sex

  98. mom and daughter

    Tracked from little sister 2009/10/03 09:02  삭제

    mom and daughter son

  99. sister sex

    Tracked from brother sister sex 2009/10/04 11:15  삭제

    fuck my sister wet wet pussy

  100. fathers fucking daughters

    Tracked from father fucks daughter 2009/10/04 12:17  삭제

    father son sex

  101. asian bdsm

    Tracked from bdsm 666 2009/10/20 10:57  삭제

    bdsm anal

  102. bdsm comix

    Tracked from bdsm drawings 2009/10/20 10:58  삭제

    bdsm ebooks

  103. bdsm stories

    Tracked from bdsm story 2009/10/21 15:25  삭제

    bdsm tgp

  104. bondage tube

    Tracked from bondage video 2009/10/21 17:57  삭제

    bondage videos

  105. bdsm fiction

    Tracked from bdsm for all 2009/10/22 13:48  삭제

    bdsm free

  106. bdsm videos

    Tracked from bdsm vids 2009/10/23 18:26  삭제

    black bdsm

  107. motrin robitussin

    Tracked from motrin hair loss 2010/11/28 13:45  삭제

    recall of children tylenol motrin

  108. father rape

    Tracked from granny rape 2011/01/07 20:20  삭제

    lesbian rape videos

  109. celebrity rape scenes

    Tracked from mature forced sex video 2011/01/08 21:47  삭제

    rape thumbnails

  110. free rape

    Tracked from hentai rape videos 2011/01/10 09:19  삭제

    mother rape

  111. brutal blowjob

    Tracked from anal rape tube 2011/01/11 09:56  삭제

    raped brides

  112. rape cases

    Tracked from mother rape 2011/01/11 11:50  삭제

    underwater forced fucking

  113. rape my body

    Tracked from forced sex pics 2011/01/12 08:03  삭제

    forced sex mpegs

  114. extreme orgasm

    Tracked from milf forced sex 2011/01/12 16:24  삭제

    rape fantasy movies

  115. extreme 3d fucking

    Tracked from forced group sex 2011/01/14 09:58  삭제

    sex stories rape

  116. hot rape scene

    Tracked from hd rape sex videoes 2011/12/23 21:41  삭제

    incest rape

Comments List

  1. perky little titties 2008/05/23 04:34

  2. bsa vintage belt buckle 2008/05/23 05:35

  3. marks adult bookmarks 2008/05/23 06:03

    洹몃

Write a comment.

[로그인][오픈아이디란?]