Search Results for 'Thread Local Storage'

ATOM Icon

1 POSTS

  1. 2009/05/11 TLS 변수 초기화 하기 by 장현준

TLS 변수 초기화 하기

TLS(Thread Local Storage)를 사용하기 위해 변수를 초기화 하려면 다음과 같은 방법을 이용하면 됩니다.

1. API 사용
DWORD dwTlsIndex;
LPVOID pData;

dwTLSIndex = TlsAlloc();

if(dwTLSIndex != TLS_OUT_OF_INDEXES)
{
	pData = (LPVOID)LocalAlloc(LPTR, 256);

	TlsSetValue(dwTlsIndex, pData);

	TlsFree(dwTlsIndex);

	CommonFunc();

	pData = TlsGetValue(dwTlsIndex);

	if(pData != NULL)
	{
		LocalFree((HLOCAL)pData);
	}
}


2. compiler keyword 사용
_declspec(thread) int g_nCount;

2번의 경우 .tls section을 이용하여 구현이 된다고 하는데, 방법이 더 쉽긴 하지만 dll의 경우 process에 attach/detach될 때 문제가 발생할 수 있기 때문에 1번을 사용하여야 된다고 합니다.
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by 장현준

2009/05/11 20:07 2009/05/11 20:07
Response
No Trackback , No Comment
RSS :
http://b4you.net/blog/rss/response/222


블로그 이미지

빗소리를 먹는 사람.

- 장현준

Notices

Archives

Authors

  1. 장현준

Recent Trackbacks

  1. 듀얼클러치의 생각 rsvin28's me2DAY 2009

Calendar

«   2012/02   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      

Site Stats

Total hits:
158026
Today:
96
Yesterday:
228