|
님의 답변에 정말 감사합니다.
동일한 쓰레드일때 발생할수가 있군요.....
제가 물어보는 의도를 정확하게 파악을 하시다니....다시한번 감사드립니다.
김지성 님이 쓰신 글 :
: 저도 한번 테스트를 해봤더니, 동일한 증상이 발생하더군요.
: 제가 해본건 간단하게 화면에 버튼 두개 놓고 누르면 EnterCriticalSection 호출 되도록
: 했습니다. 그랬더니 말씀하신 증상 나오네요.
: 해서 함 ReactOs 소스를 뒤져봤더니 요러한 부분이 있더군요..
: 별도 Thread 생성 시켜서 테스트 해보시면 CriticalSection 정상적으로 작동하는걸
: 확인 하실 수 있을겁니다.
:
: NTSTATUS
: NTAPI
: RtlEnterCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
: {
: HANDLE Thread = (HANDLE)NtCurrentTeb()->Cid.UniqueThread;
:
: /* Try to Lock it */
: if (_InterlockedIncrement(&CriticalSection->LockCount) != 0) {
:
: /*
: * We've failed to lock it! Does this thread
: * actually own it?
: */
: ///
: /// 이자리 입니다.. 동일한 쓰레드 상에서 호출하면 스킵이더군요..
: ///
: if (Thread == CriticalSection->OwningThread) {
:
: /* You own it, so you'll get it when you're done with it! No need to
: use the interlocked functions as only the thread who already owns
: the lock can modify this data. */
: CriticalSection->RecursionCount++;
: return STATUS_SUCCESS;
: }
:
: /* NOTE - CriticalSection->OwningThread can be NULL here because changing
: this information is not serialized. This happens when thread a
: acquires the lock (LockCount == 0) and thread b tries to
: acquire it as well (LockCount == 1) but thread a hasn't had a
: chance to set the OwningThread! So it's not an error when
: OwningThread is NULL here! */
:
: /* We don't own it, so we must wait for it */
: RtlpWaitForCriticalSection(CriticalSection);
: }
:
: /* Lock successful. Changing this information has not to be serialized because
: only one thread at a time can actually change it (the one who acquired
: the lock)! */
: CriticalSection->OwningThread = Thread;
: CriticalSection->RecursionCount = 1;
: return STATUS_SUCCESS;
: }
:
:
:
:
:
: 망치 님이 쓰신 글 :
: : EnterCriticalSection을 하고 루틴을 실행합니다.
: : 그리고 LeaveCriticalSection합니다.
: :
: : 그런데 아래와 같은 경우가 발생하는군요....
: :
: : //lock
: : TRACE("commbase locked 1");
: : EnterCriticalSection(&FLock);
: : TRACE("commbase locked 2 : %x", FLock);
: :
: :
: : //unlock
: : LeaveCriticalSection(&FLock);
: : TRACE("commbase unlocked : %x", FLock);
: :
: :
: : //트레이스 내용
: : 11-24 17:47:35:890 commbase locked 1
: : 11-24 17:47:35:890 commbase locked 2 : 18ebe0
: :
: : 11-24 17:47:35:937 commbase locked 1
: : 11-24 17:47:35:937 commbase locked 2 : 18ebe0
: :
: : 11-24 17:47:35:968 commbase unlocked : 18ebe0
: : 11-24 17:47:36:078 commbase unlocked : 18ebe0
: :
: :
: : 질문) EnterCriticalSection이 LeaveCriticalSection을 안했는데 두번을 들어가버리네요....
: : 이게 무슨 현상인지....이런 경우가 발생할 경우가 어떤게 있을까요?
|