검색결과 리스트
동기화에 해당되는 글 1건
- 2009.03.11 Ciritical Section을 이용한 동기화 처리법
class CCriticalSection { private: CRITICAL_SECTION m_cs; public: CCriticalSection(void) { ::InitializeCriticalSection( &m_cs ); } virtual ~CCriticalSection(void) { ::DeleteCriticalSection( &m_cs ); } void Lock(void) { ::EnterCriticalSection( &m_cs ); } void Unlock(void) { ::LeaveCriticalSection( &m_cs ); } }; |
class CSynchronized { private: CCriticalSection* m_pLock; public: CSynchronized(CCriticalSection* _pLock) : m_pLock(_pLock) { m_pLock->Lock(); } virtual ~CSynchronized(void) { m_pLock->Unlock(); } operator bool() { return false; } }; |
#define SYNCHRONIZED_BLOCK(CS) if(CSynchronized _lock = CS) {} else |
class CTest :public CCriticalSection { public: CTest(void); ~CTest(void); char temp[128]; }; |
CTest test; // 변수 선언 { CSynchronized sync( &test ); // EnterCriticalSection 실행 sprintf( test.temp, "테스트 아햏햏"); // 작업 printf("%s\n", test.temp); } // LevelCriticalSection 실행 |
CTest test; // 변수 선언 SYNCHRONIZED_BLOCK( &test ) // EnterCriticalSection 실행 { sprintf( test.temp, "테스트 아햏햏"); // 작업 printf("%s\n", test.temp); } // LevelCriticalSection 실행 |
RECENT COMMENT