Files
interactive/gms/SKBB/new_sh_statusd/test/test_sem.c
2026-08-07 17:38:18 +09:00

32 lines
401 B
C

#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
char buffer[1024];
sem_t bin_sem;
void *thread_func(void *arg)
{
while(1)
{
sem_wait(&bin_sem);
printf("you typed : %s\n", buffer);
}
}
int main()
{
pthread_t a_thread;
sem_init(&bin_sem, 0, 1);
pthread_create(&a_thread, 0, thread_func, 0);
while(1)
{
fgets(buffer, 1024, stdin);
sem_post(&bin_sem);
}
exit(1);
}