gcc로 컴파일 할 경우 -D_REENTRANT상수을 선언 하여 Thread_safe함수를 사용할 수 있도록 옵션을 꼭 사용해야
하며 -lpthread 이와 같이 Library를 링크 시켜야 한다.
* int pthread_create(pthread_t *thread,
pthread_attr_t *attr,
void *(*start_rountine)(void *),
void *arg
);
Parameter attr의 경우 일반적으로 NULL 값을 사용한다.
* int pthread_join(pthread_t thread, void **retval);
Window programming에서 WaitForSingleObject() 함수와 유사한 기능을 하는 것으로 보인다.
아래와 같이 해당 thread_function이 종료가 될 때까지 main() 함수는 대기 하게 된다.
#include <pthread.h> static void *handle_function(void *arg); int main(int argc, char **argv) { pthread_t thread_id; void *thread_retval; . . state = pthread_create(&thread_id, NULL, handle_function, NULL); . . state = pthread_join(thread_id, &thread_retval); . . return 0; } static void *handle_function(void *arg) { } |
'Embedded Linux' 카테고리의 다른 글
CodeViser의 S3C6410 Interface 설정 (0) | 2014.11.18 |
---|---|
Semaphore을 이용한 동기화 (binary semaphore) (0) | 2014.08.22 |
동기화 Mutex (0) | 2014.08.22 |
Volume was not properly unmounted ... (0) | 2014.07.24 |
Wireless Tools for Linux (0) | 2014.07.07 |