printf("ho_tari\n");
Thread2 본문
<main.c>
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
void* thread1_main(void *arg)
{
int i;
int cnt = *((int*)arg);
for (i = 0; i < cnt; i++)
{
sleep(1); puts("running thread..1");
}
return NULL;
}
void* thread2_main(void *arg)
{
int i;
int cnt = *((int*)arg);
for (i = 0; i < cnt; i++)
{
sleep(1); puts("running thread..2");
}
return NULL;
}
int main(int argc, char *argv[])
{
pthread_t t1_id, t2_id;
int thread_param = 5;
if (pthread_create(&t1_id, NULL, thread1_main, (void*)&thread_param) != 0)
{
puts("pthread_create() error");
return -1;
}
if (pthread_create(&t2_id, NULL, thread2_main, (void*)&thread_param) != 0)
{
puts("pthread_create() error");
return -1;
}
sleep(7); puts("end of main\n");
return 0;
}
<compile 결과>
'Raspberry Pi' 카테고리의 다른 글
Thread4 (0) | 2023.10.06 |
---|---|
Thread3 (0) | 2023.10.06 |
Thread1 (0) | 2023.10.05 |
SWITCH_LED_INTERRUPT (0) | 2023.10.05 |
LED_ON_OFF (0) | 2023.10.05 |