ÇÁ·Î±×·¡¹Ö

 3204, 1/161 ȸ¿ø°¡ÀÔ  ·Î±×ÀΠ 
   rider
   ¾²·¹µå »ý¼º°ü·Ã Áú¹®ÀÔ´Ï´Ù

http://www.hackerschool.org/HS_Boards/zboard.php?id=QNA_programming&no=1994 [º¹»ç]


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

int count=0; // Ä«¿îÅÍ ÃʱⰪ 0ÁöÁ¤

void *thread1(void *arg)
{
        while(count<9) // Ä«¿îÅÍ°¡ 9°¡ µÇ±â Àü±îÁö ¹Ýº¹
        {
                if(count%2==0) // ¦¼öÀÏ °æ¿ì
                {
                        printf("thread1 = %d\n", count); // thread1°ª Ãâ·Â
                        ++count; //Ä«¿îÅÍ Áõ°¡
                }
        }
        return &count; //Ä«¿îÅÍ ÁÖ¼Ò ¹Ýȯ
}

void *thread2(void *arg)
{
        while(count<10) Ä«¿îÅÍ°¡ 10ÀÌ µÇ±â Àü±îÁö ¹Ýº¹
        {
                if(count%2==1) //Ȧ¼öÀÏ °æ¿ì
                {
                        printf("thread2 = %d\n", count); //thread2°ª Ãâ·Â
            ++count; //Ä«¿îÅÍ Áõ°¡
                }
        }
        return &count; //Ä«¿îÅÍ ÁÖ¼Ò ¹Ýȯ
}

int main(int argc, char **argv)
{
        pthread_t t_id1;
        pthread_t t_id2;

        void *retval1;
        void *retval2;

        pthread_create(&t_id1, NULL, thread1, NULL); //thread1 »ý¼º
        pthread_create(&t_id2, NULL, thread2, NULL); //thread2 »ý¼º
        pthread_join(t_id1, &retval1); // t_id1 Á¾·á ±â´Ù¸²
        pthread_join(t_id2, &retval2); // t_id2 Á¾·á ±â´Ù¸²
        free(retval1); // »ý¼ºÇÑ retval1¸Þ¸ð¸®¿µ¿ªÀ» ÇØÁ¦
        free(retval2); // »ý¼ºÇÑ retval2¸Þ¸ð¸®¿µ¿ªÀ» ÇØÁ¦
        return 0;
}

½º·¹µå 2°³ »ý¼ºÇؼ­ ¦¼ö Ȧ¼öÀ϶§ 1¾¿ Áõ°¡½ÃÅ°°í

¾²·¹µå1 2 °¡ Á¾·áµÉ¶§±îÁö ´ë±âÇÏ°í

Á¾·á ÈÄ Ä«¿îÆ®°ªÀ» Ãâ·ÂÇÏ´Â ÄÚµùÀÔ´Ï´Ù.

for¹®À¸·Î ½á¼­ µ¹¸±°æ¿ì ¾ÈµÇ´Âµ¥

ÀÌÀ¯°¡ ¹»±î¿ä?.. Ä«¿îÅÍ°ªÀÌ ¾ÕÂÊ¿¡¼­ Áõ°¡Çؼ­ ±×·±°Ç°¡¿ä

ÀÌ ÄÚµùÁ» ´õ °£°áÇÏ°Ô ¼öÁ¤Á» ºÎŹµå¸³´Ï´Ù!!

  Hit : 4099     Date : 2009/04/20 09:25



    
kimth0612 count ¸¦ »ç¿ëÇϴµ¥ ¹®Á¦°¡ ÀÖÁö ¾Ê³ª¿ä? 2009/04/24  
3204   Ä¡Æ®¿£Áø °í¼öºÐ °è½Ç±î¿ä[1]     rjsdudals123
02/15 227
3203   ¿À·ù Á» ã¾ÆÁÖ¼¼¿ä [1]     marunim
05/30 954
3202   c¾ð¾î segmentation fault:11 ¿À·ù Áú¹®µå¸³´Ï´Ù![2]     leebk1124
05/21 2032
3201   C++ÇÔ¼ö°ü·Ã Áú¹®ÀÌ¿¡¿ë!![3]     1999dylee
05/11 1860
3200   ÆÄÀ̽ã Áö¹® µå¸³´Ï´Ù.[1]     kksh1107
04/24 1600
3199   ¸®¹ö½ÌÀÇ ¼¼¹ø¤Š ²É - ¿ª¶û-     nninni79
04/20 2307
3198   ´Þ°í³ª ¹®¼­ ½©ÄÚµå[1]     ghjk645
03/24 1624
3197 ºñ¹Ð±ÛÀÔ´Ï´Ù  c¾ð¾î ¼Ò¼ö °ª     adwefq
04/29 1
3196   C¾ð¾î ¼Ò½ºÁú¹®ÀÔ´Ï´Ù![5]     an0088
01/05 5185
3195   C++ /// ºôµå ¿¡·¯ ¤Ð¤Ð[1]     guichanta
08/23 2412
3194 ºñ¹Ð±ÛÀÔ´Ï´Ù  c¾ð¾î µµ¿ÍÁÖ¼¼¿ä¤Ð¤Ð     su6339
04/06 0
3193   ÇØÅ·À» ¹è¿ì·Á°íÇϴµ¥[3]     zoodem04
03/26 4190
3192   c¾ð¾î¸¦ ¹è¿ì°í½Í¾î¿ä ![7]     dwc07238
02/11 4101
3191   ½ºÅÃÀÌ ½×ÀÌ´Â ¹æÇâ¿¡ °üÇؼ­!![1]     hackxx123
12/10 3536
3190   ÇØÅ·Åø¿¡¼­ ip ¾øÀÌ Çϵ忡 ½É´Â°Å¿¡´Â ¾î¶²°Ô ÀÖÀ»±î¿ä?[2]     aowlrgmlals
11/27 4330
3189   C¾ð¾î Çϴµ¥ double ½Ç¼ö¸¦ ³ÖÀºµ¥ ÀÚ²Ù 0.0ÀÌ ³ª¿Í¿ä[2]     fatou10336
11/20 3792
3188   dumpcode.h ÀÌÇØÁ» µµ¿ÍÁÖ¼¼¿ä .[1]     cm6418
11/06 3761
3187   c¾ð¾î ¾Ë°í¸®Áò Áú¹®ÀÔ´Ï´Ù.[3]     alstn8150
10/12 3775
3186     [re] c¾ð¾î ¾Ë°í¸®Áò Áú¹®ÀÔ´Ï´Ù.     dafher
05/13 1600
3185   c¾ð¾î ¼Ò½º Áú¹® ¹¹°¡ ¹®Á¦ÀÎÁö¤Ì¤Ì¤Ì¤Ì[2]     sjjh96
05/23 4310
1 [2][3][4][5][6][7][8][9][10]..[161]

Copyright 1999-2024 Zeroboard / skin by Hackerschool.org / Secure Patch by Hackerschool.org