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
- 모의 주식
- 자바독학
- 개인프로젝트
- 백준
- Project
- 빅데이터
- Python
- backend
- C++
- 주가예측
- SNS
- java
- Reflex
- 풀스택프레임워크
- 코딩테스트
- 개발자
- 개발
- java정리
- 이웃한 칸
- 프로그램
- 자바
- 자바정리
- 코딩독학
- 프로그래밍
- 코스닥
- 사물인터넷
- frontend
- 프로그래머스
- 코테
- 코딩
Archives
- Today
- Total
Creative Code
05_THREAD2.c 본문
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
void* thread_main(void *arg);
int main(int argc, char *argv[])
{
pthread_t t_id;
int thread_param=5;
void * thr_ret;
if(pthread_create(&t_id, NULL, thread_main, (void*)&thread_param)!=0)
{
puts("pthread_create() error");
return -1;
};
if(pthread_join(t_id, &thr_ret)!=0)
{
puts("pthread_join() error");
return -1;
};
printf("Thread return message: %s \n", (char*)thr_ret);
printf("%c\n",thr_ret);
free(thr_ret);
return 0;
}
void* thread_main(void *arg)
{
int i;
int cnt=*((int*)arg);
//char * msg=(char *)malloc(sizeof(char)*50);
char msg[50];
strcpy(msg, "Hello, I'am thread~ \n");
for(i=0; i<cnt; i++)
{
sleep(1); puts("running thread");
}
return (void*)msg;
}
'Raspberry PI(C)' 카테고리의 다른 글
06_THREAD3.c (0) | 2023.10.06 |
---|---|
04_THREAD1.c (0) | 2023.10.06 |
03_THREAD.c (0) | 2023.10.06 |
02_SWITCH_LED_INTERRUPT.c (0) | 2023.10.06 |
01_LED_ON_OFF.c (0) | 2023.10.06 |