C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[55261] Re:[질문]EnterCriticalSection에서...
김지성 [kidream] 3348 읽음    2008-11-24 20:22
저도 한번 테스트를 해봤더니, 동일한 증상이 발생하더군요.
제가 해본건 간단하게 화면에 버튼 두개 놓고 누르면 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을 안했는데 두번을 들어가버리네요....
:          이게 무슨 현상인지....이런 경우가 발생할 경우가 어떤게 있을까요?

+ -

관련 글 리스트
55258 [질문]EnterCriticalSection에서... 망치 2062 2008/11/24
55261     Re:[질문]EnterCriticalSection에서... 김지성 3348 2008/11/24
55267         Re:Re:[질문]EnterCriticalSection에서...감사감사 망치 2188 2008/11/25
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.