<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mediawiki.zeropage.org/index.php?action=history&amp;feed=atom&amp;title=CeeThreadProgramming</id>
	<title>CeeThreadProgramming - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mediawiki.zeropage.org/index.php?action=history&amp;feed=atom&amp;title=CeeThreadProgramming"/>
	<link rel="alternate" type="text/html" href="https://mediawiki.zeropage.org/index.php?title=CeeThreadProgramming&amp;action=history"/>
	<updated>2026-05-15T19:01:44Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<entry>
		<id>https://mediawiki.zeropage.org/index.php?title=CeeThreadProgramming&amp;diff=30135&amp;oldid=prev</id>
		<title>imported&gt;Unknown at 05:22, 7 February 2021</title>
		<link rel="alternate" type="text/html" href="https://mediawiki.zeropage.org/index.php?title=CeeThreadProgramming&amp;diff=30135&amp;oldid=prev"/>
		<updated>2021-02-07T05:22:49Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Critical Section =&lt;br /&gt;
윈도우 유저레벨 동기화 방법. 가장 사용이 간단하다.&lt;br /&gt;
&lt;br /&gt;
= VS.NET Example =&lt;br /&gt;
MSDN 에서 대부분 예제를 가져다가 작동하게 만들었습니다. VS.NET 이상에서 작동합니다. VS6.0에서 성공하신 분 있으면 알려주세요.&lt;br /&gt;
 // crt_begthrdex.cpp&lt;br /&gt;
 //http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__beginthread.2c_._beginthreadex.asp&lt;br /&gt;
 &lt;br /&gt;
 // compile with: /MT&lt;br /&gt;
 #include &amp;amp;lt;windows.h&amp;amp;gt;&lt;br /&gt;
 #include &amp;amp;lt;stdio.h&amp;amp;gt;&lt;br /&gt;
 #include &amp;amp;lt;process.h&amp;amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 unsigned Counter; &lt;br /&gt;
 CRITICAL_SECTION cs; &lt;br /&gt;
 //http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/overlapped_str.asp&lt;br /&gt;
 &lt;br /&gt;
 unsigned __stdcall ThreadedFunction( void* pArguments )&lt;br /&gt;
 {&lt;br /&gt;
     printf( &amp;quot;In second thread...n&amp;quot; );&lt;br /&gt;
 &lt;br /&gt;
 	while ( Counter &amp;amp;lt; 100 ){&lt;br /&gt;
 		EnterCriticalSection(&amp;amp;amp;cs);&lt;br /&gt;
 		printf( &amp;quot;Thread ID %d =&amp;amp;gt; %dn&amp;quot;, pArguments, Counter);&lt;br /&gt;
 		Counter++;&lt;br /&gt;
 		LeaveCriticalSection(&amp;amp;amp;cs);&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
     _endthreadex( 0 );&lt;br /&gt;
     return 0;&lt;br /&gt;
 } &lt;br /&gt;
 &lt;br /&gt;
 int main()&lt;br /&gt;
 { &lt;br /&gt;
     HANDLE hThread, hThread2;&lt;br /&gt;
     unsigned threadID = 1;&lt;br /&gt;
 	unsigned threadID2 = 2;&lt;br /&gt;
 &lt;br /&gt;
     printf( &amp;quot;Creating second thread...n&amp;quot; );&lt;br /&gt;
 &lt;br /&gt;
     // Create the second thread.&lt;br /&gt;
     hThread = (HANDLE)_beginthreadex( NULL, 0, &amp;amp;amp;ThreadedFunction, NULL, 0, &amp;amp;amp;threadID );&lt;br /&gt;
 	hThread2 = (HANDLE)_beginthreadex( NULL, 0, &amp;amp;amp;ThreadedFunction, NULL, 0, &amp;amp;amp;threadID2 );&lt;br /&gt;
 &lt;br /&gt;
 	InitializeCriticalSection(&amp;amp;amp;cs);&lt;br /&gt;
 &lt;br /&gt;
     // Wait until second thread terminates. If you comment out the line&lt;br /&gt;
     // below, Counter will not be correct because the thread has not&lt;br /&gt;
     // terminated, and Counter most likely has not been incremented to&lt;br /&gt;
     // 1000000 yet.&lt;br /&gt;
     //WaitForSingleObject( hThread, INFINITE );&lt;br /&gt;
     //printf( &amp;quot;Counter should be 1000000; it is-&amp;amp;gt; %dn&amp;quot;, Counter );&lt;br /&gt;
 &lt;br /&gt;
 	system(&amp;quot;pause&amp;quot;);&lt;br /&gt;
     // Destroy the thread object.&lt;br /&gt;
     CloseHandle( hThread );&lt;br /&gt;
 	CloseHandle( hThread2 );&lt;br /&gt;
 	DeleteCriticalSection(&amp;amp;amp;cs);&lt;br /&gt;
 	return 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
VS.NET에서도 함수이름을 인식하지 못하는 경우 프로젝트 세팅에서 MFC라이브러리를 사용하도록 해보세요.&lt;br /&gt;
= Linux pthread =&lt;br /&gt;
 #include &amp;amp;lt;stdio.h&amp;amp;gt;&lt;br /&gt;
 #include &amp;amp;lt;stdlib.h&amp;amp;gt;&lt;br /&gt;
 #include &amp;amp;lt;pthread.h&amp;amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 void *print_message_function( void *ptr );&lt;br /&gt;
 int count= 0;&lt;br /&gt;
 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;&lt;br /&gt;
 main()&lt;br /&gt;
 {&lt;br /&gt;
 pthread_t thread1, thread2;&lt;br /&gt;
 char *message1 = &amp;quot;Thread 1&amp;quot;;&lt;br /&gt;
 char *message2 = &amp;quot;Thread 2&amp;quot;;&lt;br /&gt;
 int  iret1, iret2;&lt;br /&gt;
 &lt;br /&gt;
 /* Create independent threads each of which will execute function */&lt;br /&gt;
 &lt;br /&gt;
 iret1 = pthread_create( &amp;amp;amp;thread1, NULL, print_message_function, (voi        d*) message1);&lt;br /&gt;
 iret2 = pthread_create( &amp;amp;amp;thread2, NULL, print_message_function, (voi        d*) message2);&lt;br /&gt;
 &lt;br /&gt;
 /* Wait till threads are complete before main continues. Unless we  */&lt;br /&gt;
 /* wait we run the risk of executing an exit which will terminate   */&lt;br /&gt;
 /* the process and all threads before the threads have completed.   */&lt;br /&gt;
 &lt;br /&gt;
 pthread_join( thread1, NULL);&lt;br /&gt;
 pthread_join( thread2, NULL);&lt;br /&gt;
 &lt;br /&gt;
 printf(&amp;quot;Thread 1 returns: %d\n&amp;quot;,iret1);&lt;br /&gt;
 printf(&amp;quot;Thread 2 returns: %d\n&amp;quot;,iret2);&lt;br /&gt;
 exit(0);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 void *print_message_function( void *ptr )&lt;br /&gt;
 {&lt;br /&gt;
 char *message;&lt;br /&gt;
 message = (char *) ptr;&lt;br /&gt;
 while( count &amp;amp;lt; 100000 )&lt;br /&gt;
 {&lt;br /&gt;
 pthread_mutex_lock( &amp;amp;amp;mutex );&lt;br /&gt;
 count++;&lt;br /&gt;
 pthread_mutex_unlock( &amp;amp;amp;mutex );&lt;br /&gt;
 printf(&amp;quot;%s: %d \n&amp;quot;, message, count);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>imported&gt;Unknown</name></author>
	</entry>
</feed>