/* simple_thread.c
A simple POSIX threads example: create a thread, and then join with it.
*/
#include <pthread.h>
#include "tlpi_hdr.h"
static void *
threadFunc(void *arg)
{
char *s = arg;
printf("%s", s);
return (void *) strlen(s);
}
int
main(int argc, char *argv[])
{
pthread_t t1;
void *res;
int s;
s = pthread_create(&t1, NULL, threadFunc, "Hello world\n");
if (s != 0)
errExitEN(s, "pthread_create");
printf("Message from main()\n");
s = pthread_join(t1, &res);
if (s != 0)
errExitEN(s, "pthread_join");
printf("Thread returned %ld\n", (long) res);
exit(EXIT_SUCCESS);
}
/* detached_attrib.c
An example of the use of POSIX thread attributes (pthread_attr_t):
creating a detached thread.
*/
#include <pthread.h>
#include "tlpi_hdr.h"
static void *
threadFunc(void *x)
{
return x;
}
int
main(int argc, char *argv[])
{
pthread_t thr;
pthread_attr_t attr;
int s;
s = pthread_attr_init(&attr); /* Assigns default values */
if (s != 0)
errExitEN(s, "pthread_attr_init");
s = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (s != 0)
errExitEN(s, "pthread_attr_setdetachstate");
s = pthread_create(&thr, &attr, threadFunc, (void *) 1);
if (s != 0)
errExitEN(s, "pthread_create");
s = pthread_attr_destroy(&attr); /* No longer needed */
if (s != 0)
errExitEN(s, "pthread_attr_destroy");
s = pthread_join(thr, NULL);
if (s != 0)
errExitEN(s, "pthread_join failed as expected");
exit(EXIT_SUCCESS);
}
- 6개 thread 추가
-> Watchdog, disk service, monitor, camera service, command, sensor
- 키보드 입력을 받아서 등록된 함수 수행하도록 수정.
- 향후 메시지 테스트 용도로 활용.
"V9 (add Multi-Thread)"
https://github.com/w10sim/FIleServer_Linux_SystemProgramming