::: 강좌/소스/문서 :::

강좌/소스/문서 성격에 맞지 않는 광고,비방,질문의 글은 즉시 삭제하며
내용을 복사하여 사용할 경우 반드시 이곳(http://www.howto.pe.kr)을 출처로 명시하여 주세요


Category

  김영대(2003-03-17 02:11:11, Hit : 6155, Vote : 1630
 [Thread] pthread_cond() function

/***************************************************
*--------------------------------------------------
*   Creat  : 2001. 04. 10  (programed by Cori-Young )
*   Site: http://www.byoneself.co.kr
*   Update :
*--------------------------------------------------
*   Compile : cc -o xxx xxx.c -lpthread -lrt
*--------------------------------------------------
* Machine hardware:   sun4u
* OS version:         5.7
* Processor type:     sparc
* Hardware:           SUNW,Ultra-60
***************************************************/


#include <pthread.h>
#include <stdio.h>

void* compute_thread(void*);

pthread_mutex_t my_sync;
pthread_cond_t rx;

int thread_done = FALSE;

main()
{
         pthread_t tid;
         pthread_attr_t attr;
        
         char hello[] {"Hello, "};
         char thread[] {"thread"};

         pthread_attr_init(&attr);
        pthread_mutex_init(&my_sync,NULL);
        pthread_cond_init(&rx,NULL);
        pthread_create(&tid, &attr, compute_thread, hello);
        
         /* wait until the thread does its work */
        pthread_mutex_lock(&my_sync);
        
        while (!thread_done)
                pthread_cond_wait(&rx,&my_sync);
        
         /* When we get here, the thread has been executed */
        printf(thread);
        printf("n");
        pthread_mutex_unlock(&my_sync);
        exit(0);
}

void* compute_thread(void* dummy)
{
   pthread_mutex_lock(&my_sync);
   printf(dummy);
   thread_done = TRUE;
          pthread_cond_signal(&rx);
          pthread_mutex_unlock(&my_sync);
          return;

}





43   [Unix/Linux] [Thread] pthread_equal() function  김영대 2003/03/17 4840 1372
42   [Unix/Linux] [Thread] pthread_detach() function  김영대 2003/03/17 5267 1426
41   [Unix/Linux] [Thread] pthread_create() function  김영대 2003/03/17 5124 1352
40   [Unix/Linux] [Thread] pthread_cond_wait() function  김영대 2003/03/17 4842 1323
39   [Unix/Linux] [Thread] pthread_cond_timedwait() function  김영대 2003/03/17 6041 1783
38   [Unix/Linux] [Thread] pthread_cond_signal() function  김영대 2003/03/17 4338 1194
37   [Unix/Linux] [Thread] pthread_cond_init() function  김영대 2003/03/17 5553 1514
36   [Unix/Linux] [Thread] pthread_cond_destroy() function  김영대 2003/03/17 4685 1243
35   [Unix/Linux] [Thread] pthread_cond_broadcast() function  김영대 2003/03/17 4809 1395
34   [Unix/Linux] [Thread] pthread_condattr_destroy() function  김영대 2003/03/17 4675 1348
  [Unix/Linux] [Thread] pthread_cond() function  김영대 2003/03/17 6155 1630
32   [Unix/Linux] [Thread] pthread_cleanup_push() function  김영대 2003/03/17 5015 1447
31   [Unix/Linux] [Thread] pthread_cleanup_pop() function  김영대 2003/03/17 5016 1480
30   [Unix/Linux] [Thread] pthread_cancel() function  김영대 2003/03/17 5962 1700
29   [Unix/Linux] [Thread] pthread_attr_setinheritsched() function  김영대 2003/03/17 5195 1456
28   [Unix/Linux] [Thread] pthread_attr_setdetachstate() function  김영대 2003/03/17 5409 1539
27   [Unix/Linux] [Thread] pthread_attr_init() function  김영대 2003/03/17 4866 1382
26   [Unix/Linux] [Thread] pthread_attr_getschedparam() function  김영대 2003/03/17 5008 1416
25   [Unix/Linux] [Thread] pthread_attr_getinheritsched() function  김영대 2003/03/17 5061 1559
24   [Unix/Linux] [Thread] pthread_attr_getdetachstate() function  김영대 2003/03/17 5120 1490

[1][2][3][4][5][6][7] 8 [9][10]
 

Copyright 1999-2020 Zeroboard / skin by zero