Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
POSIX Threads
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
HORINOUCHI Masato
October 06, 2015
Technology
59
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
POSIX Threads
社内LT大会 0x64物語 #01 Parallel / Concurrent 資料
HORINOUCHI Masato
October 06, 2015
More Decks by HORINOUCHI Masato
See All by HORINOUCHI Masato
balenaCloud
thermes
0
93
Church Numerals
thermes
0
53
CPS & CTO
thermes
0
250
FM synthesis
thermes
0
39
A440
thermes
0
65
Inside mml2wav.rb
thermes
0
91
Scheme Interpreter in Ruby
thermes
0
72
Clock / Timer
thermes
0
170
Hash Tree
thermes
0
80
Other Decks in Technology
See All in Technology
ポケモンの型をTypeScriptの型システムで表現してみた
subroh0508
0
370
RSA暗号を手計算したくなること、ありますよね?? (20260615_orestudy6_rsa)
thousanda
0
300
新しいVibe Codingと”自走”について
watany
6
300
FinOps × AIエージェントで実現する コストインシデントの自動調査
oasis1994liveforever
0
130
日本 Fintech 未来予測レポート 2027〜2028年(手動編集版)
8maki
0
2.1k
脆弱性対応、どこで線を引くか
rymiyamoto
1
370
AmazonRoute 53ではじめてのドメイン取得!HTTPS化までの道のりを整理してみた
usanchuu
3
130
FDE という解 ― 暗黙知と明示知をつなぐ、伴走型エンジニアリング ―
otanet
0
140
How Timee Delivers Day 1 Production Ready LLM Features
tomoyks
0
150
Dario Amodi『Policy on the AI Exponential』を理解する
nagatsu
0
230
2026.06.13_AI時代に事業会社が「SIer出身エンジニア」を求める理由 / Why Businesses Seek Engineers with a System Integrator Background in the AI Era
jumtech
0
1.1k
白金鉱業Meetup_Vol.24_「AIエージェントは分けるほど良い」は本当か? / Is it true that “the more you divide AI agents, the better”?
brainpadpr
1
310
Featured
See All Featured
The untapped power of vector embeddings
frankvandijk
2
1.8k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
230
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
420
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
エンジニアに許された特別な時間の終わり
watany
107
250k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
Abbi's Birthday
coloredviolet
2
8k
It's Worth the Effort
3n
188
29k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
370
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
160
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
GitHub's CSS Performance
jonrohan
1033
470k
Transcript
POSIX Threads 2015/10/06 0x64 Tales #01 Parallel / Concurrent Livesense
Inc. HORINOUCHI Masato
pthread ͬͯͳʹ? (1) • ਖ਼໊ࣜশ POSIX Threads Ͱɺͦͷ໊ͷ௨Γ POSIX ඪ४ͷඇಉ
ظॲཧ(thread)ͷ API ܈ɻ • ༷ IEEE Std 1003.1c-1995 Ͱఆ͍ٛͯ͠Δɻ • API ܈ͳͷͰ༻͢ΔݴޠΘͳ͍ɻ • جຊతʹ Cݴޠ͚ͷϥΠϒϥϦʔΛ֤ݴޠʹҠ২ɻ
pthread ͬͯͳʹ? (2) • ͋͘·Ͱ API Λنఆ͍ͯ͠Δ͚ͩͳͷͰɺͲͷΑ͏ͳ࣮͔ OS (ਖ਼֬ʹ Kernel
ͱ Library) ʹΑΔɻ • POSIX४ڌͷγεςϜͰ͋Ε༻Ͱ͖ΔͷͪΖΜɺ Win32 ࣮͋ͬͨΓ͢Δɻ • ͨͩ͠ 3rd party (ݱঢ় RedHat)ɻ
Linux ͷεϨου • ͱ͜ΖͰ "Linux kernel ͷεϨουͬͯ݁ہϓϩηε" ͬͯ Λฉ͍ͨ͜ͱͳ͍Ͱ͔͢Ͷɻ •
ࠓճ͜ͷΛ؆୯ʹઆ໌͢Δ͜ͱʹ͠·͢ɻ
pthread σϞ • ৯ࣄ͢Δֶऀͷ Λ͍ͯΈΑ͏ɻ • source Sun Studio
12 ͷϖʔδ ͔Β͖࣋ͬͯ·ͨ͠ɻ • din_philo.c σουϩοΫͷՄೳੑ͋Γɻ • din_philo_fix1.c τʔΫϯ (ηϚϑΥ) Λ༻͍ͯσου ϩοΫΛղܾ͍ͯ͠Δɻ
ps -Lf UID PID PPID LWP C NLWP STIME TTY
TIME CMD horinou+ 21135 1804 21135 0 6 16:51 pts/1 00:00:00 ./din_philo horinou+ 21135 1804 21136 0 6 16:51 pts/1 00:00:00 ./din_philo horinou+ 21135 1804 21137 0 6 16:51 pts/1 00:00:00 ./din_philo horinou+ 21135 1804 21138 0 6 16:51 pts/1 00:00:00 ./din_philo horinou+ 21135 1804 21139 0 6 16:51 pts/1 00:00:00 ./din_philo horinou+ 21135 1804 21140 0 6 16:51 pts/1 00:00:00 ./din_philo • PID (process ID) ͕ಉҰͰ LWP (thread ID) ͕ҧ͏εϨουΛ 5 ͭੜͰ͖ͨɻ
Linux ͷ pthreads ࣮ • Ϟμϯͳ Linux + glibc Ͱ
Na/ve POSIX Threads Library (NPTL) ͕༻͍ΒΕΔɻ • ॳظͷ Linux 2.6 Ͱ LinuxThreads ͕༻͍ΒΕ͍ͯͨɻ • ΑΓલϢʔβʔϥϯυͰ࣮͍ͯͨ͠ (໊শෆ໌)ɻ • Lightweight Process (LWP) Λ༻࣮͍ͯͯ͠͠Δɻ • LWP ෳͷ LWPಉ࢜ͰϦιʔεΛڞ༗͢Δ͜ͱ͕Մೳɻ
NPTL • LWP ͱεϨου͕ 1:1 ͷ࣮ɺ͍ΘΏΔ 1:1 ϞσϧΛ࠾༻ɻ • ͦΕͧΕͷεϨου͕
Kernel εέδϡʔϧ࣮ମʹ 1:1 Ϛοϐ ϯάͱͳΔɻ • ϓϩηεεϨου (LWP) task_struct ߏମͰཧ͠ɺ ϓϩηεεέδϡʔϦϯάಉҰͷΩϡʔͰߦͳ͏ɻ • ཁ͢ΔʹϓϩηεͱεϨουͷҧ͍΄ͱΜͱͳ͍ɻ
ϓϩηεͱεϨουͷϝϞϦཧ • ϓϩηε • fork ࣌ʹ৽͘͠ԾΞυϨεۭؒΛੜ͠ͷϝϞϦΛࢠʹ ίϐʔɻ • εϨου •
ෳͷεϨου͕ 1ͭͷԾΞυϨεۭؒΛڞ༗ɻ
ϓϩηεͷԾΞυϨεۭؒ ϚϧνεϨουͷίϯςΩετΓସ͑ʹ͏ίετ ͔ΒҾ༻ɻ
εϨουͷԾΞυϨεۭؒ ϚϧνεϨουͷίϯςΩετΓସ͑ʹ͏ίετ ͔ΒҾ༻ɻ
NPTL ͷར • kernel ͔ΒεϨουϓϩηε(1:1Ϟσϧ)ͱͯ͠ѻ͑Δͷ Ͱ… • 1ͭͷϓϩηεεέδϡʔϥʔ͚ͩͰཧ͢ΔͷͰγϯϓ ϧɻ •
SMP γεςϜͰෳͷίΞͰεϨουͷฒྻॲཧΛ͢Δͷ ͕؆୯ɻ
Linux Ҏ֎ͩͱ • ͪͳΈʹ Linux Ҏ֎ͷ POSIX γεςϜ M:N Ϟσϧ࠾༻ྫ͕
ଟ͍ɻ • FreeBSD • Kernel Scheduler En;;es (KSE) • Solaris • Solaris Lightweight Process (LWP)
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠