|
||
0
0
Array¿¡ ´ã¾Æ¼ ±×°É ´Ù½Ã µ¹¸®¸é¼ join°É¸é µÇ°Ú½À´Ï´Ù.
2015-05-18
|
0
0
¸¶Äí¸®Äí¸®
¾î¶»°ÔÇؾßÇÏÁÒ ¤Ì¤Ì
Thread th[5]; for(int i=0; i<5; i++) { th[i].start(); } for(int i=0; i<5; i++) { th[i].join(); } Console.WriteLine("Thread terminated"); ÀÌ·¸°Ô ÇϸéµÇ³ª¿ä?.... |
0
0
º½-º½
¿ëµµ¿¡ ¸Â°Ô ¾²·Á¸é TPL ¾²´Â°ÍÀÌ ÁÁ½À´Ï´Ù.
½ÇÁ¦ °ü¸®°¡ ¾î·Á¿î Thread º¸´Ù´Â TPL »ç¿ëÀ» ±ÇÀåÇÏ°í ÀÖ±¸¿ä. »ç¿ë¹ý ÀÚüµµ ¸Å¿ì °£´ÜÇÕ´Ï´Ù. ¾Æ·¡¿Í °°ÀÌ ¾²¸é µË´Ï´Ù. private void button1_Click(object sender, EventArgs e) { Console.WriteLine("start"); Parallel.For(0, 5, i => { threadMethod(i); }); Console.WriteLine("end"); } private void threadMethod(int i) { for (int j = 0; j < 1000; j++) Console.WriteLine("thread " + i.ToString() + " value " + j); } |
0
0
¸¶Äí¸®Äí¸®
ParallelÀ» Àû¿ëÇغ¸¾Ò½À´Ï´Ù...
0ºÎÅÍ ~ 4±îÁö ¾²·¹µå°¡ µ¿ÀÛÇÏ´Â °ÍÀº ¸ÂÀ¸³ª.. 0¹ø½º·¹µå°¡ Á¾·áµÇ¸é 1¹ø ½º·¹µå°¡ È£ÃâµÇ°í ÇÏ´Â ½ÄÀ¸·Î µ¿ÀÛÀÌ µÇ³×¿ä ¤Ì¤Ì ¹¹°¡ ¹®Á¦Àϱî¿ä ¤Ð¤Ð |
0
0
º½-º½
´Ù½ÃÇѹø for ·çÇÁ¸¦ Á»´õ ±æ°Ô Àâ¾Æ¼ Å×½ºÆ® Çغ¸¼¼¿ä. 0¹ø ¾²·¹µå°¡ ¹Ì¹¦ÇÏ°Ô ´õ »¡¸® ¼öÇàµÇ´Ï±ñ..´ëºÎºÐ 0¹ø ¾²·¹µå°¡ ¸ÕÀú ³¡³³´Ïµð¸¸ Àý´ë 0¹ø³¡³ª°í ´ÙÀ½¿¡ 1¹ø ¾²·¹µå ¼öÇàµÇ°í ÇÏÁö ¾Ê½À´Ï´Ù. ¶Ç´Â wihle·Î ¹«ÇÑ ·çÇÁ¿¡ ºüÁö°Ô ÇÏ°í º¸¼Åµµ µË´Ï´Ù. ½ÇÁ¦ Å×½ºÆ® ÇÏ°í Á¤»ó¼öÇà È®ÀÎÇÏ°í ¿Ã·Áµå¸° »ùÇÃÄÚµå ÀÔ´Ï´Ù.
|
0
0
¾²·¹µå°¡ ¹ºÁö ºÎÅÍ °í¹ÎÇغ¸¼¼¿ä....
http://ko.wikipedia.org/wiki/%EC%8A%A4%EB%A0%88%EB%93%9C http://www.hanbit.co.kr/network/view.html?bi_id=239 |
0
0
ÇÔÇغ¸±×·Î
½ÃÄö½º·Î º¸¸é..... ´ÙÀ½°ú °°°í¿ä
1) ³ ¸ÞÀÎ ÇÁ·Î¼¼½º¾ß. 2) ¾²·¹µå 5°³¸¦ ¸¸µé°í ½Í¾î. 2-1) ¾²·¹µå th1 ¸¦ ¸¸µé·¡ -> th1 µ¿ÀÛ -> Á¾·á 2-2) ¾²·¹µå th2 ¸¦ ¸¸µé·¡ -> th2 µ¿ÀÛ -> Á¾·á 2-3) ¾²·¹µå th3 ¸¦ ¸¸µé·¡ -> th3 µ¿ÀÛ -> Á¾·á 2-4) ¾²·¹µå th4 ¸¦ ¸¸µé·¡ -> th4 µ¿ÀÛ -> Á¾·á 2-5) ¾²·¹µå th5 ¸¦ ¸¸µé·¡ -> th5 µ¿ÀÛ -> Á¾·á 3) ¸ÞÀÎ ÇÁ·Î¼¼½º Á¾·á. ½Ã°£ ¼øÀ¸·Î º¸¸é 1) ³ ¸ÞÀÎ ÇÁ·Î¼¼½º¾ß. 2) ¾²·¹µå 5°³¸¦ ¸¸µé°í ½Í¾î. 2-1) ¾²·¹µå th1 ¸¦ ¸¸µé·¡ 2-2) ¾²·¹µå th2 ¸¦ ¸¸µé·¡ 2-3) ¾²·¹µå th3 ¸¦ ¸¸µé·¡ 2-4) ¾²·¹µå th4 ¸¦ ¸¸µé·¡ 2-5) ¾²·¹µå th5 ¸¦ ¸¸µé·¡ 3) ¸ÞÀÎ ÇÁ·Î¼¼½º Á¾·á. 3-1) th1 µ¿ÀÛ -> Á¾·á 3-2) th2 µ¿ÀÛ -> Á¾·á 3-3) th3 µ¿ÀÛ -> Á¾·á 3-4) th4 µ¿ÀÛ -> Á¾·á 3-5) th5 µ¿ÀÛ -> Á¾·á ÀÌ·¸°Ô º¯°æ ÇÏ¼Å¾ß µÇ°Ú½À´Ï´Ù. 1) ³ ¸ÞÀÎ ÇÁ·Î¼¼½º¾ß. 2) ¾²·¹µå 5°³¸¦ ¸¸µé°í ½Í¾î. 2-1) ¾²·¹µå th1 ¸¦ ¸¸µé·¡ -> th1 µ¿ÀÛ -> Á¾·á 2-2) ¾²·¹µå th2 ¸¦ ¸¸µé·¡ -> th2 µ¿ÀÛ -> Á¾·á 2-3) ¾²·¹µå th3 ¸¦ ¸¸µé·¡ -> th3 µ¿ÀÛ -> Á¾·á 2-4) ¾²·¹µå th4 ¸¦ ¸¸µé·¡ -> th4 µ¿ÀÛ -> Á¾·á 2-5) ¾²·¹µå th5 ¸¦ ¸¸µé·¡ -> th5 µ¿ÀÛ -> Á¾·á 3) th1,2,3,4,5 ¸¦ ±â´Ù·Á¾ßÁö... 4) ¸ÞÀÎ ÇÁ·Î¼¼½º Á¾·á. |
0
0
ÇÔÇغ¸±×·Î
Âü°í·Î ÀÌ·¸°Ô Çϼŵµ th1~5 Áß¿¡ ´©°¡ ¸ÕÀú ¼öÇà µÉÁö´Â ±×¶§±×¶§ ¸¶´Ù ´Ù¸£°Ô µË´Ï´Ù.
¾²·¹µå·Î ¿¬¼ÓÀûÀ¸·Î Â÷·ÊÂ÷·Ê ÂïÈ÷°í ½Í´Ù¸é °øÀ¯ ¶ôÀ» ¸¸µé¾î¼ ¾²·¹µå ¼öÇà ÇÒ ¶§ Å°¸¦ ¾ò¾úÀ» ¶§ Â÷·ÊÀûÀ¸·Î ¼öÇà µÇµµ·Ï ¸¸µé¾î¾ß ÇÕ´Ï´Ù. ÀÌ·² °Å¶ó¸é Â÷¶ó¸® ¾²·¹µå ¾øÀÌ ¼öÇà ÇÏ´Â°Ô ÁÁ°ÚÁÒ. °øºÎÇϽô °Å¶ó¸é ±¤¹üÀ§ÇÏ°Ô Çѹø Å×½ºÆ® Çغ¸½Ã°í¿ä ±×°Ô ¾Æ´Ï¶ó¸é ³»°¡ ¸¸µé°íÀÚ ÇÏ´Â ±â´É¿¡ ¿Ö ¾²·¹µå¸¦ ½á¾ß Çϴ°¡? ¸¦ °õ°õÀÌ »ý°¢ÇØ º¸½Ã¸é ÁÁÀ» °Í °°¾Æ¿ä |
0
0
ÇÁÇÁÀaÇÁÇÁÇÁ
private Object lockObj = new Object();
private int threadCnt = 0; for(int i=0; i<5; i++) { Thread th = new Thread(threadMethod); th.start(); } private void threadMethod() { Lock (lockObj) { // ÇØ´ç ¸Þ¼Òµå ³»¿ë // threadCnt++; if (threadCnt >= 5) { Console.WriteLine("Thread Terminated"); threadCnt = 0; } } } ÀÌ·¸°Ô ÇÏ½Ã¸é ¼øÂ÷ÀûÀ¸·Î ÁøÇà µË´Ï´Ù. ¼øÂ÷ÀûÀÎ ÁøÇàÀÌ ÇÊ¿ä¾øÀ¸½Ã¸é ±×³É lock¸¸ »©¼¼¿ä |
0
0
±õ»ó´Ô
¸ÖƼ¾²·¹µùÀ» ÇϽ÷Á´Â°Çµ¥,
5°³ÀÇ ¾²·¹µå°¡ ¼øÂ÷°¡ ¾Æ´Ñ µ¿½Ã¿¡ µ¹°í ½ÍÀ¸½Å°ÅÁö¿ä? ±×·¸´Ù¸é, ½ÇÇàÇÒ ½º·¹µå ³»ºÎ¿¡¼ ·ÎÁ÷ÀÌ Á¾·áµÇ°í ¸Ç ¸¶Áö¸·¿¡, ÄݹéÇÔ¼ö¸¦ È£ÃâÇϵµ·Ï ÇϸéµË´Ï´Ù. ´Ù¸¥ ºÐµé ¸»¾¸ÇϽŰÍó·³, Àü¿ªº¯¼ö·Î counting¼ýÀÚ¸¦ Áֽðí, ¿©±â¼´Â 5°¡ µÇ°ÚÁÒ. ±×·³ 5°³ÀÇ ¾²·¹µå°¡ °¢ÀÚ µ¹¸é¼, °¢±â ³¡³¯¶§¸¶´Ù °°Àº ÇϳªÀÇ ÇÔ¼ö¸¦ ½ÇÇàÇϵµ·Ï Çϴ°̴ϴÙ. ÀÌ ÇÔ¼ö´Â ´ëÃæ ÀÌ·¸°ÚÁÒ counting--; if(counting == 0){ Console.WriteLine("Thread Terminated"); } ¾²·¹µå Çϳª Á¾·áµÉ¶§¸¶´Ù ÇÔ¼ö¸¦ È£ÃâÇؼ, ¼ýÀÚ°¡ ÁÙ¾îµé °ÍÀÌ°í, ±×°Ô 0À̵Ǹé, Á¾·á¹®±¸°¡ ³ª¿À°ÚÁÒ. 5°³ÀÇ ¾²·¹µå´Ï±ñ, 5¹øÀÇ ÇÔ¼ö°¡ È£ÃâµÇ°Ú±¸¿ä~ ´ëÃæ callbackÀ» ÀÌ¿ëÇϴ°ÅÁö¿ä. ¾Æ¸¶µµ joinÀ̶õ ±â´Éµµ callbackÀÏ ²®´Ï´Ù. ½º·¹µå°¡ Á¾·áµÇ¸é, Á¾·áÀ̺¥Æ®°¡ ¹ß»ýÇϸé, ÄݹéÇÔ¼ö¸¦ È£ÃâÇϴ°ÅÁö¿ä. ȤÀº ´Ù¸¥ºÐµé ¸»Ã³·³ ¾²·¹µå ¹è¿À» »ý¼ºÇÏ°í, ¾²·¹µå Á¾·á½Ã, Çϳª¾¿ ½½¶óÀ̽º ½ÃÄÑÁà¼, ¹è¿±æÀÌ°¡ 0ÀÌ µÇ¸é Á¾·áµµ µÇ°Ú³×¿ä |
0
0
ÀÌÃ¥ÀÓ
µ¿±âÈ °´Ã¼¸¦ »ç¿ëÇϽʽÿÀ.
C#Àº ¾ÈÇغÁ¼ Àß ¸ð¸£°Ú´Âµ¥ ¼¼¸¶Æ÷¾î³ª À̺¥Æ® °°Àº°Å ÀÖÁö ¾Ê³ª¿ä? °¢ ¾²·¹µå ³»ºÎ Æã¼Ç¿¡¼ ŽºÅ© ½ºÄÉÁ층ÀÌ ¹ß»ýÇÏ´Â ÇÔ¼ö »ç¿ëÇÏ½Ã°í ¾²·¹µå Á¾·áÇÒ ¶§ ¼¼¸¶Æ÷¾î¿¡ ½Ã±×³Î ÁÖ°ÔÇÏ°í, Äֿܼ¡ Ãâ·ÂÇÏ´Â ÇÔ¼ö ¾Õ¿¡ ¼¼¸¶Æ÷¾î ±â´Ù¸®´Â ÇÔ¼ö »ç¿ëÇÏ¸é °¡´ÉÇÒ°Å °°Àºµ¥¿ä. C#¿¡ ¼¼¸¶Æ÷¾î°¡ ÀÖ³ª? |
0 0 ÀÌÃ¥ÀÓ |
|
|
¡â ÀÌÀü±Û¡ä ´ÙÀ½±Û | ¸ñ·Ïº¸±â |