로그인

검색

API/MFC
2013.07.28 02:58

스레드(CreateThread), EVENT 동기화

MoA
조회 수 3939 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄

Thread 출처 : http://wory.tistory.com/166

Event 동기화 출처 : http://blog.naver.com/drrich/20054322126


#include <Windows.h>
#include <stdio.h> 
#include <conio.h> 

// HANDLE 
HANDLE event = NULL; 

// Thread_Func 
DWORD WINAPI Thread_Func(PVOID vparam) 

    int* state = (int*)vparam; 
    int count = 0; 
    while ((*state)) { 
        // 신호 대기 
        WaitForSingleObject(event, INFINITE); 
        // 진행 
        printf("Thread_Func : %dn", count); 
        count++; 
        // 스레드 종료 신호 
        SetEvent(event); 
        Sleep(100); 
    } 
    (*state) = 2; 
    return 0; 


// main 
int main() 

    HANDLE    thread = NULL; 
    int        state  = 1; 
    // 이벤트 생성 
    event = CreateEvent(NULL, 0, 0, NULL); 
    SetEvent(event); 
    // 스레드 생성 
    DWORD id; 
    thread = CreateThread(NULL, 0, &Thread_Func, &state, 0, &id); 
    // 메인 루프 
    while (1) { 
        // 신호 대기 
        WaitForSingleObject(event, INFINITE); 
        // 진행 
        printf("main...n"); 
        // 종료 
        if (_kbhit() && getch()=='p') { 
            state=0; 
        } 
        if (state==2) break; 
        // 스레드 종료 신호 
        SetEvent(event); 
        Sleep(100); 
    } 
    // 스레드 강제 종료 
    if (state==1) TerminateThread(thread, 0); 
    // 이벤트 종료 
    SetEvent(event); 
    CloseHandle(event); 
}


http://blog.naver.com/cor2738/150111130866

?

  1. Programming 게시판 관련

    Date2014.11.01 CategoryTool/etc ByMoA Views15453
    read more
  2. 큰 수 구하기 알고리즘

    Date2012.08.02 CategoryAlgorithm ByNaya Views3302
    Read More
  3. Simple Add-On Wait Dialog in MFC

    Date2013.11.21 CategoryAPI/MFC ByMoA Views3305
    Read More
  4. [농장게임 만들기] 4. 펜스를 그리자

    Date2014.04.30 CategoryPython ByMoA Views3305
    Read More
  5. [액션게임 만들기] 6. 게임 화면 출력

    Date2014.05.07 CategoryPython ByMoA Views3308
    Read More
  6. 구글 검색 알고리즘의 원리

    Date2012.08.02 CategoryAlgorithm ByNaya Views3309
    Read More
  7. extern "C" 에 관하여

    Date2013.07.28 CategoryC/C++ ByMoA Views3317
    Read More
  8. [액션게임 만들기] 5. 장면 전환

    Date2014.05.07 CategoryPython ByMoA Views3321
    Read More
  9. Simplified Logger Class

    Date2013.07.28 CategoryC/C++ ByMoA Views3326
    Read More
  10. Redmine 설치

    Date2013.07.28 CategoryTool/etc ByMoA Views3330
    Read More
  11. MFC에서 생성,사용되는 파일 확장자

    Date2013.08.30 CategoryAPI/MFC ByMoA Views3335
    Read More
  12. GetLastInputInfo 함수

    Date2013.12.06 CategoryAPI/MFC ByMoA Views3337
    Read More
  13. Which Font is the default for MFC Dialog Controls

    Date2013.06.12 CategoryAPI/MFC ByMoA Views3345
    Read More
  14. 에디트 플러스, VS 2008 컴파일 환경 설정

    Date2013.07.28 CategoryTool/etc ByMoA Views3355
    Read More
  15. [액션게임 만들기] 10. 캐릭터 기술 구현

    Date2014.05.07 CategoryPython ByMoA Views3362
    Read More
  16. What does set -e mean in a bash script?

    Date2021.04.29 CategoryTool/etc ByOBG Views3366
    Read More
  17. 스레드 강좌 + CreateThread() 와 _beginthreadex() 함수의 차이

    Date2013.07.28 CategoryAPI/MFC ByMoA Views3378
    Read More
  18. CString class

    Date2013.07.28 CategoryAPI/MFC ByMoA Views3382
    Read More
  19. Windows 10 앱 개발(UWP)

    Date2015.10.13 CategoryAPI/MFC ByMoA Views3382
    Read More
  20. Start Something! - Windows 8 개발 공식 사이트

    Date2012.08.02 CategorySite ByNaya Views3390
    Read More
  21. fopen 함수가 Multi Thread 에서 안전한가?

    Date2013.07.28 CategoryC/C++ ByMoA Views3391
    Read More
Board Pagination Prev 1 ... 5 6 7 8 9 10 11 12 13 14 15 Next
/ 15