Code Snippets/Boost2010. 8. 20. 12:31

1. 뮤텍스 사용법 - 간단





2. condition 변수 간단 사용법


3. 컨디션 변수 사용하여 Multi Reader & Single Writer


참조
- http://www.boost.org/doc/libs/1_44_0/doc/html/thread.html
- http://aszt.inf.elte.hu/~gsd/klagenfurt/material/ch03s06.html
- http://www.kmonos.net/alang/boost/classes/thread.html

'Code Snippets > Boost' 카테고리의 다른 글

함수 호출 연기 & 함수 타입 캐스팅  (0) 2010.09.17
Nested Bind  (0) 2010.09.09
Generalized Function Pointers  (0) 2010.09.06
boost::bind 활용  (0) 2010.09.03
boost 관련 유용한 링크 모음  (0) 2010.08.20
Posted by codevania
DirectX2010. 7. 29. 12:56

http://msdn.microsoft.com/en-us/library/bb147224(VS.85).aspx

결론부터 말하자면, 윈도우 프로시저와 같은 스레드에서만 아래 4가지 D3D 함수가 호출되어야 한다는 것이다.
전체화면에서 창모드로 바뀔 때, 권한과 이것과 관련한 내부적인 critical section유지에 관련한 이유 때문이다.

결론을 뒷받침할 만한 내용은 다음과 같다...

D3D 몇가지 함수들은 window message들을 처리하는 스레드에서만 호출할 수 있도록 설계되어있다.
이 몇가지 함수들은 다음 4가지다.
  • IDirect3DDevice9::Reset
  • IDirect3D9::CreateDevice
  • IDirect3DDevice9::TestCooperativeLevel
  • the final Release of IDirect3DDevice9

왜 저렇게 설계되었냐면...

멀티스레드 어플리케이션은 window message 처리 스레드들을 D3D 스레드들에서 강력하게 분리하려한다.
이런 어플리케이션, 즉 display mode 변환이 발생하는 스레드와 D3D 호출 스레드가 분리된 어플리케이션은
deadlock의 위험이 있기 때문이다.

Posted by codevania
Troubleshooting2010. 7. 27. 11:50
define에 의한 문제를 해결할 때 참고할 만한 내용이다.

문제는... 아래 코드는 컴파일 되지 않는다는 것이다.
#include <limits>
#include <windows.h>
void main()
{
     std::numeric_limits< float >::max(); 
}
에러 메세지를 보면...
1>d:\programming\test\main.cpp(5) : warning C4003: not enough actual parameters for macro 'max'
1>d:\programming\test\main.cpp(5) : error C2589: '(' : illegal token on right side of '::'
1>d:\programming\test\main.cpp(5) : error C2143: syntax error : missing ';' before '::' 

이유는 windef.h에 정의된 다음과 같이 min, max 가 define되어 있기 때문이다.

#ifndef NOMINMAX

#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif

#ifndef min
#define min(a,b)            (((a) < (b)) ? (a) : (b))
#endif

#endif  /* NOMINMAX */


여기를 보면 3가지 해결 방안이 나온다.

1. 괄호로 싸버린다.
std::numeric_limits< float >::max();   ->  (std::numeric_limits< float >::max)();

2. undefine 해버린다.
#include <limits>
#include <windows.h>
#undef max
void main()
{
    std::numeric_limits< float >::max(); 
}

3. NOMINMAX를 define한다.
#define NOMINMAX
#include <limits>
#include <windows.h>
void main()
{
    std::numeric_limits< float >::max(); 
}


MS MVP님께서 추천하는 방법은 다음과 같다.
#define NOMINMAX
#include <windows.h>
#include <limits>
#include <algorithm>

template< typename T >
inline T max(const T & a, const T & b) { return std::max(a, b); }

template< typename T >
inline T min(const T & a, const T & b) { return std::min(a, b); }

void main()
{
    std::numeric_limits< float >::max(); 
}

'Troubleshooting' 카테고리의 다른 글

Break when an exception is  (0) 2010.12.03
마일스 사운드 버그  (3) 2010.11.17
intrin.h errors  (0) 2010.10.28
using namespace std;  (0) 2010.10.27
#include <windows.h>  (0) 2010.10.26
Posted by codevania