pthread_setcancelstate(3) - wariua/manpages-ko GitHub Wiki
pthread_setcancelstate, pthread_setcanceltype - ์ทจ์ ๊ฐ๋ฅ์ฑ ์ํ์ ์ ํ ์ค์ ํ๊ธฐ
#include <pthread.h>
int pthread_setcancelstate(int state, int *oldstate);
int pthread_setcanceltype(int type, int *oldtype);
-pthread
๋ก ๋งํฌ.
pthread_setcancelstate()
๋ ํธ์ถ ์ค๋ ๋์ ์ทจ์ ๊ฐ๋ฅ์ฑ ์ํ๋ฅผ state
์ ์ค ๊ฐ์ผ๋ก ์ค์ ํ๋ค. ์ค๋ ๋์ ์ด์ ์ทจ์ ๊ฐ๋ฅ์ฑ ์ํ๋ฅผ oldstate
๊ฐ ๊ฐ๋ฆฌํค๋ ๋ฒํผ๋ก ๋ฐํํ๋ค. state
์ธ์๋ ๋ค์ ๊ฐ๋ค ์ค ํ๋์ฌ์ผ ํ๋ค.
PTHREAD_CANCEL_ENABLE
- ์ค๋ ๋๊ฐ ์ทจ์ ๊ฐ๋ฅํ๋ค. ์ต์ด ์ค๋ ๋๋ฅผ ํฌํจํ ๋ชจ๋ ์ ์ค๋ ๋์ ๊ธฐ๋ณธ ์ทจ์ ๊ฐ๋ฅ์ฑ ์ํ์ด๋ค. ์ค๋ ๋์ ์ทจ์ ๊ฐ๋ฅ์ฑ ์ ํ์ด ์ต์ ๊ฐ๋ฅ ์ค๋ ๋๊ฐ ์ทจ์ ์์ฒญ์ ์ธ์ ๋ฐ์ํ๊ฒ ๋ ์ง ๊ฒฐ์ ํ๋ค.
PTHREAD_CANCEL_DISABLE
- ์ค๋ ๋๊ฐ ์ทจ์ ๊ฐ๋ฅํ์ง ์๋ค. ์ทจ์ ์์ฒญ์ ์์ ํ๋ฉด ์ทจ์ ๊ฐ๋ฅ์ฑ์ด ํ์ฑํ๋ ๋๊น์ง ๋ง์ ๋๋ค.
pthread_setcanceltype()
์ ํธ์ถ ์ค๋ ๋์ ์ทจ์ ๊ฐ๋ฅ์ฑ ์ ํ์ type
์ ์ค ๊ฐ์ผ๋ก ์ค์ ํ๋ค. ์ค๋ ๋์ ์ด์ ์ทจ์ ๊ฐ๋ฅ์ฑ ์ ํ์ oldtype
์ด ๊ฐ๋ฆฌํค๋ ๋ฒํผ๋ก ๋ฐํํ๋ค. type
์ธ์๋ ๋ค์ ๊ฐ๋ค ์ค ํ๋์ฌ์ผ ํ๋ค.
PTHREAD_CANCEL_DEFERRED
- ์ค๋ ๋๊ฐ ์ทจ์์ (pthreads(7) ์ฐธ๊ณ )์ธ ํจ์๋ฅผ ํธ์ถํ ๋๊น์ง ์ทจ์ ์์ฒญ์ ์ฐ๊ธฐํ๋ค. ์ต์ด ์ค๋ ๋๋ฅผ ํฌํจํ ๋ชจ๋ ์ ์ค๋ ๋์ ๊ธฐ๋ณธ ์ทจ์ ๊ฐ๋ฅ์ฑ ์ ํ์ด๋ค.
PTHREAD_CANCEL_ASYNCHRONOUS
- ์ค๋ ๋๊ฐ ์ธ์ ๋ ์ทจ์๋ ์ ์๋ค. (๋ณดํต์ ์ทจ์ ์์ฒญ ์์ ์ฆ์ ์ทจ์๋์ง๋ง ์์คํ ์์ ์ด๋ฅผ ๋ณด์ฅํ์ง๋ ์๋๋ค.)
์ด ํจ์๋ค ๊ฐ๊ฐ์ด ์ํํ๋ ์ค์ ํ๊ธฐ-์ป๊ธฐ ๋์์ ๊ฐ์ ํจ์๋ฅผ ํธ์ถํ๋ ํ๋ก์ธ์ค ๋ด ๋ค๋ฅธ ์ค๋ ๋์ ๋ํด ์์์ ์ด๋ค.
์ฑ๊ณต ์ ์ด ํจ์๋ค์ 0์ ๋ฐํํ๋ค. ์ค๋ฅ ์ 0 ์๋ ์ค๋ฅ ๋ฒํธ๋ฅผ ๋ฐํํ๋ค.
pthread_setcancelstate()
๊ฐ ๋ค์ ์ค๋ฅ๋ก ์คํจํ ์ ์๋ค.
EINVAL
-
state
์ ์ ํจํ์ง ์์ ๊ฐ.
pthread_setcanceltype()
์ด ๋ค์ ์ค๋ฅ๋ก ์คํจํ ์ ์๋ค.
EINVAL
-
type
์ ์ ํจํ์ง ์์ ๊ฐ.
์ด ์ ์์ ์ฌ์ฉํ๋ ์ฉ์ด๋ค์ ๋ํ ์ค๋ช ์ attributes(7)๋ฅผ ๋ณด๋ผ.
์ธํฐํ์ด์ค | ์์ฑ | ๊ฐ |
---|---|---|
pthread_setcancelstate() ,pthread_setcanceltype()
|
์ค๋ ๋ ์์ ์ฑ | MT-Safe |
pthread_setcancelstate() ,pthread_setcanceltype()
|
๋น๋๊ธฐ ์ทจ์ ์์ ์ฑ | AC-Safe |
POSIX.1-2001, POSIX.1-2008.
์ค๋ ๋๊ฐ ์ทจ์๋ ๋ ์ด๋ค ์ผ์ด ์ผ์ด๋๋์ง์ ๋ํ ์์ธํ ๋ด์ฉ์ pthread_cancel(3)์ ๋ณด๋ผ.
์ทจ์ ์์ฒญ์ผ๋ก ์ค๋จ๋ผ์ ์ ๋๋ ์ด๋ค ์ค์ํ ๋์์ ์ค๋ ๋์์ ์ํํ ๋ ์ทจ์ ๊ฐ๋ฅ์ฑ์ ์ ์ ๊บผ ๋๋ ๊ฒ ์ ์ฉํ๋ค. ๊ธด ๊ธฐ๊ฐ ๋์, ๋๋ ์ค๋ ๋ธ๋ก ํ ์ ์๋ ๋์์์ ์ทจ์ ๊ฐ๋ฅ์ฑ์ ๋์ง ์๋๋ก ์กฐ์ฌํด์ผ ํ๋ค. ์ค๋ ๋๊ฐ ์ทจ์ ์์ฒญ์ ๋ฌต๋ฌต๋ถ๋ต์ด ๋๋ค.
์ทจ์ ๊ฐ๋ฅ์ฑ ์ ํ์ PTHREAD_CANCEL_ASYNCHRONOUS
๋ก ์ค์ ํ๋ ๊ฒ ์ ์ฉํ ๊ฒฝ์ฐ๋ ์ ์๋ค. ์ค๋ ๋๊ฐ ์ธ์ ๋ ์ทจ์๋ ์ ์์ผ๋ฏ๋ก ์์ ํ๊ฒ ์์์ ์์ฝ(๊ฐ๋ น malloc(3)์ผ๋ก ๋ฉ๋ชจ๋ฆฌ ํ ๋น)ํ๊ฑฐ๋ ๋ฎคํ
์ค๋ ์ธ๋งํฌ์ด, ๋ฝ ๋ฑ์ ํ๋ํ ์ ์๋ค. ์์ ์์ฝ์ด ์์ ํ์ง ์์ ์ด์ ๋ ์ค๋ ๋๊ฐ ์ทจ์๋ ๋ ๊ทธ ์์๋ค์ ์ํ๊ฐ ์ด๋ค์ง๋ฅผ (์ฆ ์์ ์์ฝ ์ ์ ์ทจ์๊ฐ ์ผ์ด๋ฌ๋์ง, ์๋๋ฉด ์์ฝํ ์ํ์์, ๋๋ ํด์ ํ ํ์ ์ผ์ด๋ฌ๋์ง๋ฅผ) ์์ฉ์์ ์ ๋ฐฉ๋ฒ์ด ์๊ธฐ ๋๋ฌธ์ด๋ค. ๋ํ ํจ์ ํธ์ถ ์ค์ ์ทจ์๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ ์ด๋ค ๋ด๋ถ ์๋ฃ ๊ตฌ์กฐ(๊ฐ๋ น malloc(3) ๊ณ์ด ํจ์๋ค์์ ๊ด๋ฆฌํ๋ ์ ํด ๋ธ๋ก ์ฐ๊ฒฐ ๋ฆฌ์คํธ)๊ฐ ๋น์ผ๊ด ์ํ๋ก ๋จ์ ์๋ ์๋ค. ๊ทธ ๊ฒฐ๊ณผ ์ ๋ฆฌ ํธ๋ค๋ฌ๊ฐ ๋๋ ์ธ๋ชจ๊ฐ ์๊ฒ ๋๋ค.
์์ ํ๊ฒ ๋น๋๊ธฐ์ ์ผ๋ก ์ทจ์ํ ์ ์๋ ํจ์๋ฅผ ๋น๋๊ธฐ ์ทจ์ ์์ ํจ์๋ผ๊ณ ๋ถ๋ฅธ๋ค. POSIX.1-2001๊ณผ POSIX.1-2008์์๋ pthread_cancel(3), pthread_setcancelstate()
, pthread_setcanceltype()
์ด ๋น๋๊ธฐ ์ทจ์ ์์ ์ด๊ธฐ๋ง์ ์๊ตฌํ๋ค. ์ผ๋ฐ์ ์ผ๋ก ๋น๋๊ธฐ์ ์ผ๋ก ์ทจ์๋ ์ ์๋ ์ค๋ ๋์์ ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํจ์๋ค์ ์์ ํ๊ฒ ํธ์ถํ ์ ์๋ค.
๋น๋๊ธฐ ์ทจ์ ๊ฐ๋ฅ์ฑ์ด ์ธ๋ชจ ์๋ ๋ช ์ ๋๋ ๊ฒฝ์ฐ ์ค ํ๋๋ ์์ํ ์ฐ์ฐ ์์ฃผ ๋ฃจํ ๋ด์ ์๋ ์ค๋ ๋๋ฅผ ์ทจ์ํ ๋์ด๋ค.
๋ฆฌ๋
์ค ์ค๋ ๋ฉ ๊ตฌํ์์๋ pthread_setcancelstate()
์ oldstate
์ธ์๊ฐ NULL์ธ ๊ฒ์ ํ์ฉํ๋ฉฐ, ๊ทธ ๊ฒฝ์ฐ ์ด์ ์ทจ์ ๊ฐ๋ฅ์ฑ ์ํ์ ๋ํ ์ ๋ณด๊ฐ ํธ์ถ์์๊ฒ ๋ฐํ๋์ง ์๋๋ค. ๋ค๋ฅธ ์ฌ๋ฌ ๊ตฌํ์์๋ NULL์ธ oldstate
์ธ์๋ฅผ ํ์ฉํ๋ค. ํ์ง๋ง POSIX.1์์๋ ์ด ์ ์ ๋ช
์ธํ๊ณ ์์ง ์์ผ๋ฏ๋ก ์ด์ ๊ฐ๋ฅํ ์์ฉ์์๋ ํญ์ oldstate
์ NULL ์๋ ๊ฐ์ ์ง์ ํ๋ ๊ฒ ์ข๋ค. ์ ํํ ๊ฐ์ ๋ด์ฉ์ด pthread_setcanceltype()
์ oldtype
์ธ์์๋ ์ ์ฉ๋๋ค.
pthread_cancel(3) ์ฐธ๊ณ .
pthread_cancel(3), pthread_cleanup_push(3), pthread_testcancel(3), pthreads(7)
2017-09-15