pthread_cond_destroy(3p) - wariua/manpages-ko GitHub Wiki

PROLOG

์ด ๋งค๋‰ด์–ผ ํŽ˜์ด์ง€๋Š” POSIX ํ”„๋กœ๊ทธ๋ž˜๋จธ ๋งค๋‰ด์–ผ์˜ ์ผ๋ถ€์ด๋‹ค. ์ด ์ธํ„ฐํŽ˜์ด์Šค์˜ ๋ฆฌ๋ˆ…์Šค ๊ตฌํ˜„์— ์ฐจ์ด๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ (์ƒ์„ธํ•œ ๋ฆฌ๋ˆ…์Šค ๋™์ž‘ ๋ฐฉ์‹์€ ํ•ด๋‹น ๋ฆฌ๋ˆ…์Šค ๋งค๋‰ด์–ผ ํŽ˜์ด์ง€ ์ฐธ๊ณ ) ๋ฆฌ๋ˆ…์Šค์—์„œ ์ด ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ๊ตฌํ˜„๋˜์–ด ์žˆ์ง€ ์•Š์„ ์ˆ˜๋„ ์žˆ๋‹ค.

NAME

pthread_cond_destroy, pthread_cond_init - ์กฐ๊ฑด ๋ณ€์ˆ˜ ํŒŒ๊ธฐ ๋ฐ ์ดˆ๊ธฐํ™”

SYNOPSIS

#include <pthread.h>

int pthread_cond_destroy(pthread_cond_t *cond);
int pthread_cond_init(pthread_cond_t *restrict cond,
    const pthread_condattr_t *restrict attr);
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

DESCRIPTION

pthread_cond_destroy() ํ•จ์ˆ˜๋Š” cond๊ฐ€ ๋‚˜ํƒ€๋‚ด๋Š” ์กฐ๊ฑด ๋ณ€์ˆ˜๋ฅผ ํŒŒ๊ธฐํ•œ๋‹ค. ๊ทธ ๊ฐ์ฒด๋ฅผ ์ดˆ๊ธฐํ™” ์•ˆ ๋œ ์ƒํƒœ๋กœ ๋งŒ๋“œ๋Š” ํšจ๊ณผ๊ฐ€ ์žˆ๋‹ค. ๊ตฌํ˜„ ์‹œ pthread_cond_destroy()์—์„œ cond๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๋Š” ๊ฐ์ฒด๋ฅผ ๋น„์œ ํšจ ๊ฐ’์œผ๋กœ ์„ค์ •ํ•˜๋„๋ก ํ•  ์ˆ˜๋„ ์žˆ๋‹ค. ํŒŒ๊ธฐ๋œ ์กฐ๊ฑด ๋ณ€์ˆ˜ ๊ฐ์ฒด๋ฅผ pthread_cond_init()์œผ๋กœ ๋‹ค์‹œ ์ดˆ๊ธฐํ™” ํ•  ์ˆ˜ ์žˆ๋‹ค. ํŒŒ๊ธฐ๋œ ๊ฐ์ฒด๋ฅผ ๊ทธ ์™ธ ๋ฐฉ์‹์œผ๋กœ ์ฐธ์กฐํ•˜๋Š” ๊ฒฐ๊ณผ๋Š” ๊ทœ์ •๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค.

ํ˜„์žฌ ์–ด๋–ค ์Šค๋ ˆ๋“œ๋„ ๋ธ”๋ก ๋˜์–ด ์žˆ์ง€ ์•Š์€ ์ดˆ๊ธฐํ™” ๋œ ์กฐ๊ฑด ๋ณ€์ˆ˜๋ฅผ ํŒŒ๊ธฐํ•˜๋Š” ๊ฒƒ์€ ์•ˆ์ „ํ•˜๋‹ค. ํ˜„์žฌ ๋‹ค๋ฅธ ์Šค๋ ˆ๋“œ๊ฐ€ ๋ธ”๋ก ๋˜์–ด ์žˆ๋Š” ์กฐ๊ฑด ๋ณ€์ˆ˜๋ฅผ ํŒŒ๊ธฐํ•˜๋ ค๋Š” ์‹œ๋„์˜ ๊ฒฐ๊ณผ๋Š” ๊ทœ์ •๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค.

pthread_cond_init() ํ•จ์ˆ˜๋Š” cond๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๋Š” ์กฐ๊ฑด ๋ณ€์ˆ˜๋ฅผ attr์ด ๊ฐ€๋ฆฌํ‚ค๋Š” ์†์„ฑ๋“ค๋กœ ์ดˆ๊ธฐํ™” ํ•œ๋‹ค. attr์ด NULL์ด๋ฉด ๊ธฐ๋ณธ ์กฐ๊ฑด ๋ณ€์ˆ˜ ์†์„ฑ๋“ค์„ ์‚ฌ์šฉํ•œ๋‹ค. ์ฆ‰ ๊ธฐ๋ณธ ์กฐ๊ฑด ๋ณ€์ˆ˜ ์†์„ฑ ๊ฐ์ฒด์˜ ์ฃผ์†Œ๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๊ฒƒ๊ณผ ํšจ๊ณผ๊ฐ€ ๊ฐ™๋‹ค. ์ดˆ๊ธฐํ™” ์„ฑ๊ณต ์‹œ ์กฐ๊ฑด ๋ณ€์ˆ˜๋Š” ์ดˆ๊ธฐํ™” ๋œ ์ƒํƒœ๊ฐ€ ๋œ๋‹ค.

๋™๊ธฐํ™” ์ˆ˜ํ–‰์—๋Š” cond ์ž์ฒด๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. cond์˜ ์‚ฌ๋ณธ์„ pthread_cond_wait(), pthread_cond_timedwait(), pthread_cond_signal(), pthread_cond_broadcast(), pthread_cond_destroy() ํ˜ธ์ถœ์—์„œ ์ฐธ์กฐํ•˜๋Š” ๊ฒฐ๊ณผ๋Š” ๊ทœ์ •๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค.

์ด๋ฏธ ์ดˆ๊ธฐํ™” ๋œ ์กฐ๊ฑด ๋ณ€์ˆ˜๋ฅผ ์ดˆ๊ธฐํ™” ํ•˜๋ ค๋Š” ์‹œ๋„์˜ ๊ฒฐ๊ณผ๋Š” ๊ทœ์ •๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค.

๊ธฐ๋ณธ ์กฐ๊ฑด ๋ณ€์ˆ˜ ์†์„ฑ๋“ค์ด ์ ํ•ฉํ•œ ๊ฒฝ์šฐ์—๋Š” ๋งคํฌ๋กœ PTHREAD_COND_INITIALIZER๋ฅผ ์จ์„œ ์กฐ๊ฑด ๋ณ€์ˆ˜๋ฅผ ์ดˆ๊ธฐํ™” ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋งค๊ฐœ๋ณ€์ˆ˜ attr์„ NULL๋กœ ์ง€์ •ํ•ด pthread_cond_init()์„ ํ˜ธ์ถœํ•˜๋Š” ๋™์  ์ดˆ๊ธฐํ™”์™€ ํšจ๊ณผ๊ฐ€ ๋™๋“ฑํ•˜๋˜ ์˜ค๋ฅ˜ ๊ฒ€์‚ฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์ ์ด ๋‹ค๋ฅด๋‹ค.

pthread_cond_destroy()์˜ cond ์ธ์ž๋กœ ์ง€์ •ํ•œ ๊ฐ’์ด ์ดˆ๊ธฐํ™” ๋œ ์กฐ๊ฑด ๋ณ€์ˆ˜๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ณ  ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ์˜ ๋™์ž‘ ๋ฐฉ์‹์€ ๊ทœ์ •๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค.

pthread_cond_init()์˜ attr ์ธ์ž๋กœ ์ง€์ •ํ•œ ๊ฐ’์ด ์ดˆ๊ธฐํ™” ๋œ ์กฐ๊ฑด ๋ณ€์ˆ˜ ์†์„ฑ ๊ฐ์ฒด๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ณ  ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ์˜ ๋™์ž‘ ๋ฐฉ์‹์€ ๊ทœ์ •๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค.

RETURN VALUE

์„ฑ๊ณต ์‹œ pthread_cond_destroy()์™€ pthread_cond_init() ํ•จ์ˆ˜๋Š” 0์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ์•„๋‹ˆ๋ฉด ์˜ค๋ฅ˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์˜ค๋ฅ˜ ๋ฒˆํ˜ธ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

ERRORS

๋‹ค์Œ ๊ฒฝ์šฐ์— pthread_cond_init() ํ•จ์ˆ˜๊ฐ€ ์‹คํŒจํ•œ๋‹ค.

EAGAIN
์กฐ๊ฑด ๋ณ€์ˆ˜๋ฅผ ์ƒˆ๋กœ ์ดˆ๊ธฐํ™” ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ (๋ฉ”๋ชจ๋ฆฌ ์™ธ์˜) ์ž์›์ด ์‹œ์Šคํ…œ์— ๋ถ€์กฑํ•˜๋‹ค.
ENOMEM
์กฐ๊ฑด ๋ณ€์ˆ˜๋ฅผ ์ดˆ๊ธฐํ™” ํ•˜๊ธฐ์— ์ถฉ๋ถ„ํ•œ ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์—†๋‹ค.

์ด ํ•จ์ˆ˜๋“ค์€ ์˜ค๋ฅ˜ ์ฝ”๋“œ [EINTR]์„ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š๋Š”๋‹ค.

์ดํ•˜๋Š” ๊ทœ๋ฒ”์ ์ด์ง€ ์•Š์€ ๋‚ด์šฉ์ด๋‹ค.

EXAMPLES

์กฐ๊ฑด ๋ณ€์ˆ˜์— ๋ธ”๋ก ๋˜์–ด ์žˆ๋Š” ์Šค๋ ˆ๋“œ๊ฐ€ ๋ชจ๋‘ ๊นจ์–ด๋‚œ ์งํ›„์— ์กฐ๊ฑด ๋ณ€์ˆ˜๋ฅผ ํŒŒ๊ธฐํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ๋ณด์ž.

struct list {
    pthread_mutex_t lm;
    ...
}

struct elt {
    key k;
    int busy;
    pthread_cond_t notbusy;
    ...
}

/* ๋ฆฌ์ŠคํŠธ ํ•ญ๋ชฉ์„ ์ฐพ์•„์„œ ์˜ˆ์•ฝ */
struct elt *
list_find(struct list *lp, key k)
{
    struct elt *ep;

    pthread_mutex_lock(&lp->lm);
    while ((ep = find_elt(l, k) != NULL) && ep->busy)
        pthread_cond_wait(&ep->notbusy, &lp->lm);
    if (ep != NULL)
        ep->busy = 1;
    pthread_mutex_unlock(&lp->lm);
    return(ep);
}

delete_elt(struct list *lp, struct elt *ep)
{
    pthread_mutex_lock(&lp->lm);
    assert(ep->busy);
    ... ๋ชฉ๋ก์—์„œ ep ์ œ๊ฑฐ ...
    ep->busy = 0;  /* ํŽธ์ง‘์ฆ */
(A) pthread_cond_broadcast(&ep->notbusy);
    pthread_mutex_unlock(&lp->lm);
(B) pthread_cond_destroy(&ep->notbusy);
    free(ep);
}

์ด ์˜ˆ์—์„œ, (A ํ–‰) ์กฐ๊ฑด ๋ณ€์ˆ˜์— ๋Œ€๊ธฐ ์ค‘์ธ ์Šค๋ ˆ๋“œ๋ฅผ ๋ชจ๋‘ ๊นจ์šด ์งํ›„์— (B ํ–‰) ์กฐ๊ฑด ๋ณ€์ˆ˜์™€ ๊ทธ ๋ฆฌ์ŠคํŠธ ํ•ญ๋ชฉ์„ ํ•ด์ œํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ฎคํ…์Šค์™€ ์ฝ”๋“œ ๋•Œ๋ฌธ์— ์‚ญ์ œํ•  ํ•ญ๋ชฉ์„ ๋‹ค๋ฅธ ์Šค๋ ˆ๋“œ๊ฐ€ ๊ฑด๋“œ๋ฆด ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

APPLICATION USAGE

์—†์Œ.

RATIONALE

pthread_cond_destroy()์˜ cond ์ธ์ž๋กœ ์ง€์ •ํ•œ ๊ฐ’์ด ์ดˆ๊ธฐํ™” ๋œ ์กฐ๊ฑด ๋ณ€์ˆ˜๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ณ  ์žˆ์ง€ ์•Š์Œ์„ ๊ตฌํ˜„์—์„œ ๊ฐ์ง€ํ•˜๋Š” ๊ฒฝ์šฐ ํ•จ์ˆ˜๋ฅผ ์‹คํŒจ ์ฒ˜๋ฆฌํ•˜๊ณ  [EINVAL] ์˜ค๋ฅ˜๋ฅผ ๋ณด๊ณ ํ•˜๊ธฐ๋ฅผ ๊ถŒ์žฅํ•œ๋‹ค.

pthread_cond_destroy()๋‚˜ pthread_cond_init()์˜ cond ์ธ์ž๋กœ ์ง€์ •ํ•œ ๊ฐ’์„ ๋‹ค๋ฅธ ์Šค๋ ˆ๋“œ๊ฐ€ ์‚ฌ์šฉ ์ค‘์ž„์„ (๊ฐ€๋ น pthread_cond_wait() ํ˜ธ์ถœ ๋‚ด์— ์žˆ์Œ์„), ๋˜๋Š” pthread_cond_init()์˜ cond ์ธ์ž๋กœ ์ง€์ •ํ•œ ๊ฐ’์ด ์ด๋ฏธ ์ดˆ๊ธฐํ™” ๋œ ์กฐ๊ฑด ๋ณ€์ˆ˜๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ณ  ์žˆ์Œ์„ ๊ตฌํ˜„์—์„œ ๊ฐ์ง€ํ•˜๋Š” ๊ฒฝ์šฐ ํ•จ์ˆ˜๋ฅผ ์‹คํŒจ ์ฒ˜๋ฆฌํ•˜๊ณ  [EBUSY] ์˜ค๋ฅ˜๋ฅผ ๋ณด๊ณ ํ•˜๊ธฐ๋ฅผ ๊ถŒ์žฅํ•œ๋‹ค.

pthread_cond_init()์˜ attr ์ธ์ž๋กœ ์ง€์ •ํ•œ ๊ฐ’์ด ์ดˆ๊ธฐํ™” ๋œ ์กฐ๊ฑด ๋ณ€์ˆ˜ ์†์„ฑ ๊ฐ์ฒด๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ณ  ์žˆ์ง€ ์•Š์Œ์„ ๊ตฌํ˜„์—์„œ ๊ฐ์ง€ํ•˜๋Š” ๊ฒฝ์šฐ ํ•จ์ˆ˜๋ฅผ ์‹คํŒจ ์ฒ˜๋ฆฌํ•˜๊ณ  [EINVAL] ์˜ค๋ฅ˜๋ฅผ ๋ณด๊ณ ํ•˜๊ธฐ๋ฅผ ๊ถŒ์žฅํ•œ๋‹ค.

pthread_mutex_destroy()๋„ ์ฐธ๊ณ ํ•˜๋ผ.

FUTURE DIRECTIONS

์—†์Œ.

SEE ALSO

pthread_cond_broadcast(), pthread_cond_timedwait(), pthread_mutex_destroy()

POSIX.1-2008 Base Definitions ๊ถŒ, <pthread.h>

COPYRIGHT

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, Copyright (C) 2013 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. (This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.unix.org/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


2013

โš ๏ธ **GitHub.com Fallback** โš ๏ธ