Enginius/Linux
리눅스에서 쓰레드 컴파일하고 실행하기
해리s
2011. 7. 28. 22:04
쓰레드를 만드는 소스
#include#include #include #include pthread_t p[3]; void *child1(void *arg) { while(1); } int main(int argc, char** argv) { int err; if ( err = pthread_create(&p[0], NULL, child1, NULL) ) printf("child 1 was not born\n"); if ( err = pthread_create(&p[1], NULL, child1, NULL) ) printf("child 2 was not born\n"); if ( err = pthread_create(&p[2], NULL, child1, NULL) ) printf("child 3 was not born\n"); printf("This is a parent\n"); sleep(10); exit(0); }
위와 같이 파일을 만든 후에 다음과 같이 컴파일을 한다.
# gcc -o test test.c -pthread
컴파일 한 후에는
# ./test
로 실행을 한다.