Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- C++
- 모의 주식
- 프로그램
- 코딩독학
- 코딩
- 코테
- 백준
- 개인프로젝트
- Project
- SNS
- 풀스택프레임워크
- 개발자
- frontend
- 사물인터넷
- 코딩테스트
- 자바정리
- 빅데이터
- 자바독학
- java정리
- Reflex
- 코스닥
- 주가예측
- 이웃한 칸
- java
- 개발
- 프로그래밍
- 자바
- 프로그래머스
- backend
- Python
Archives
- Today
- Total
Creative Code
03_THREAD.c 본문
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
// 스레드에서 실행되는 함수
void* thread_main(void *arg)
{
int i;
int cnt = *((int*)arg);
for (i = 0; i < cnt; i++)
{
sleep(1);
puts("running thread\n"); // 스레드에서 실행 중인 메시지 출력
}
return NULL;
}
int main(int argc, char *argv[])
{
pthread_t t_id;
int thread_param = 5;
// 스레드 생성
if (pthread_create(&t_id, NULL, thread_main, (void*)&thread_param) != 0)
{
puts("pthread_create() error\n");
return -1;
}
sleep(7);
puts("end of main\n"); // 메인 스레드에서 실행 중인 메시지 출력
return 0;
}
'Raspberry PI(C)' 카테고리의 다른 글
06_THREAD3.c (0) | 2023.10.06 |
---|---|
05_THREAD2.c (0) | 2023.10.06 |
04_THREAD1.c (0) | 2023.10.06 |
02_SWITCH_LED_INTERRUPT.c (0) | 2023.10.06 |
01_LED_ON_OFF.c (0) | 2023.10.06 |