메뉴 건너뛰기

OBG

Programming

API/MFC
2013.07.28 02:58

스레드(CreateThread), EVENT 동기화

MoA
조회 수 615 추천 수 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 Views1732
    read more
  2. Synology: Top Best Apps For Docker

    Date2024.07.01 CategoryTool/etc ByOBG Views4
    Read More
  3. PEFT: Parameter-Efficient Fine-Tuning of Billion-Scale Models on Low-Resource Hardware

    Date2024.04.15 CategoryLLM ByOBG Views17
    Read More
  4. [VESSL AI] 뉴욕주민의 프로젝트플루토 — LLM, LLMOps를 활용한 금융 미디어의 혁신

    Date2024.04.21 CategoryLLM ByOBG Views18
    Read More
  5. Anthropic, LLM의 내부를 이해하는데 있어 상당한 진전을 보임

    Date2024.06.03 CategoryLLM ByOBG Views18
    Read More
  6. A Beginner's Guide to Prompt Engineering with GitHub Copilot

    Date2024.04.04 CategoryLLM ByOBG Views21
    Read More
  7. How LLMs Work ? Explained in 9 Steps — Transformer Architecture

    Date2024.04.11 CategoryLLM ByOBG Views23
    Read More
  8. ChatGPT의 강력한 경쟁 언어모델 등장!, Mixtral 8x7B

    Date2024.04.14 CategoryLLM ByOBG Views23
    Read More
  9. Mixture of Experts - Part 2

    Date2024.04.14 CategoryLLM ByOBG Views24
    Read More
  10. llama3 implemented from scratch

    Date2024.05.24 CategoryLLM ByOBG Views25
    Read More
  11. ASCII 3D 렌더러 만들기

    Date2024.06.03 CategoryGraphic ByOBG Views26
    Read More
  12. 만능 프롬프트

    Date2024.04.07 CategoryLLM ByOBG Views28
    Read More
  13. The difference between quantization methods for the same bits

    Date2024.04.14 CategoryLLM ByOBG Views28
    Read More
  14. [ifkakao] 추천 시스템: 맥락과 취향 사이 줄타

    Date2024.01.10 CategoryDeeplearning ByOBG Views31
    Read More
  15. Getting Started with Sentiment Analysis using Python

    Date2024.04.11 CategoryLLM ByOBG Views31
    Read More
  16. Real-Time Stock News Sentiment Prediction with Python

    Date2024.04.11 CategoryLLM ByOBG Views31
    Read More
  17. HuggingFace 공동창업자가 추천하는 AI 분야 입문 서적

    Date2024.05.24 CategoryTool/etc ByOBG Views33
    Read More
  18. [12월 1주] 떠오르는 '미스트랄 7B'...'라마 2' 이어 한국어 모델 세대교체 주도

    Date2024.03.05 CategoryLLM ByOBG Views35
    Read More
  19. Using Machine Learning to Predict Customers’ Next Purchase Day

    Date2024.02.27 CategoryDeeplearning ByOBG Views40
    Read More
  20. 멀티-플레이어 게임 서버와 레이턴시 보상 테크닉

    Date2024.01.16 Category서버 ByOBG Views45
    Read More
  21. 마이크로소프트가 공개한 무료 AI 코스들

    Date2023.11.28 CategoryDeeplearning ByOBG Views56
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15
위로