검색결과 리스트
Thread에 해당되는 글 3건
- 2013.08.21 [Java] ThreadLocal
- 2013.06.19 [.Net] Thread Pool
- 2008.09.27 GetExitCodeThread 로 스레드의 상태를 알아보기
글
'Java > Java' 카테고리의 다른 글
[Java] enum에 대해서 (0) | 2013.12.24 |
---|---|
[Java] Java Garbage Collection (0) | 2013.11.28 |
[Java] JDBC SQL Server 연결 URL (0) | 2013.07.18 |
[Java] 윈도우 JDK 버전 확인 (0) | 2013.05.10 |
[Java] jar 파일 실행 시키기 (0) | 2013.04.07 |
트랙백
댓글
글
링크 : http://msdn.microsoft.com/ko-kr/library/3dasc8as(v=vs.80).aspx
using System;
using System.Threading;
public class Fibonacci
{
public Fibonacci(int n, ManualResetEvent doneEvent)
{
_n = n;
_doneEvent = doneEvent;
}
// Wrapper method for use with thread pool.
public void ThreadPoolCallback(Object threadContext)
{
int threadIndex = (int)threadContext;
Console.WriteLine("thread {0} started...", threadIndex);
_fibOfN = Calculate(_n);
Console.WriteLine("thread {0} result calculated...", threadIndex);
_doneEvent.Set();
}
// Recursive method that calculates the Nth Fibonacci number.
public int Calculate(int n)
{
if (n <= 1)
{
return n;
}
return Calculate(n - 1) + Calculate(n - 2);
}
public int N { get { return _n; } }
private int _n;
public int FibOfN { get { return _fibOfN; } }
private int _fibOfN;
private ManualResetEvent _doneEvent;
}
public class ThreadPoolExample
{
static void Main()
{
const int FibonacciCalculations = 10;
// One event is used for each Fibonacci object
ManualResetEvent[] doneEvents = new ManualResetEvent[FibonacciCalculations];
Fibonacci[] fibArray = new Fibonacci[FibonacciCalculations];
Random r = new Random();
// Configure and launch threads using ThreadPool:
Console.WriteLine("launching {0} tasks...", FibonacciCalculations);
for (int i = 0; i < FibonacciCalculations; i++)
{
doneEvents[i] = new ManualResetEvent(false);
Fibonacci f = new Fibonacci(r.Next(20,40), doneEvents[i]);
fibArray[i] = f;
ThreadPool.QueueUserWorkItem(f.ThreadPoolCallback, i);
}
// Wait for all threads in pool to calculation...
WaitHandle.WaitAll(doneEvents);
Console.WriteLine("All calculations are complete.");
// Display the results...
for (int i= 0; i<FibonacciCalculations; i++)
{
Fibonacci f = fibArray[i];
Console.WriteLine("Fibonacci({0}) = {1}", f.N, f.FibOfN);
}
}
}
'.Net > .Net' 카테고리의 다른 글
[.Net] Regular Expression Quick Reference (0) | 2013.09.12 |
---|---|
[.Net] 런타임에서 어셈블리를 찾는 방법 (0) | 2013.05.20 |
[.Net] 닷넷프레임워크 버전 확인 (0) | 2013.05.10 |
[.Net] TransactedInstaller (0) | 2013.04.22 |
[.Net] Windows Service Current Directory (0) | 2013.04.20 |
트랙백
댓글
글
예)
사실 GetExitCodeThread는 스레드 핸들을 인자로 해서 스레드 종료코드를 알아내는 함수이다.
그렇지만 스레드가 종료되기전 GetExitCodeThread를 호출하면 종료코드에 'STILL_ACTIVE'가
담겨져 있다 따라서 스레드가 실행중인지 확인 할 수 있다.
<br>
if (m_hThread)
{
DWORD dwExitCode = 0;
::GetExitCodeThread(m_hThread, &dwExitCode);
if (dwExitCode == STILL_ACTIVE)
{
AfxMessageBox(_T("실행중인 스레드"));
}
}
사실 GetExitCodeThread는 스레드 핸들을 인자로 해서 스레드 종료코드를 알아내는 함수이다.
그렇지만 스레드가 종료되기전 GetExitCodeThread를 호출하면 종료코드에 'STILL_ACTIVE'가
담겨져 있다 따라서 스레드가 실행중인지 확인 할 수 있다.
'OS > Windows' 카테고리의 다른 글
CoInitialize(), CoUninitialize() 호출시 주의사항 (0) | 2009.02.03 |
---|---|
Release에서 디버깅 하기 ... (0) | 2008.11.21 |
InternetSetOption의 Timeout 설정 버그 (0) | 2008.09.16 |
WM_DESTROY 메세지 (0) | 2008.07.21 |
초보 DLL 사용하기 (0) | 2008.02.21 |
RECENT COMMENT