diff --git a/08_12_thread/2.mymutexthread_st.c b/08_12_thread/2.mymutexthread_st.c deleted file mode 100644 index 0b15b7e1721f7edb0f52494e49b6bd654c96351d..0000000000000000000000000000000000000000 --- a/08_12_thread/2.mymutexthread_st.c +++ /dev/null @@ -1,87 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <pthread.h> -#include <sys/types.h> -#include <errno.h> - -#include <unistd.h> -#include <sys/syscall.h> - -void * thread_function(void *); - -int Counter=0; -#ifndef NOMUTEX -.... mutex_id; -#endif - -int main(void) -{ - pthread_t tid1, tid2; - void *thread_result; - -#ifndef NOMUTEX - if(________(&mutex_id, NULL) != 0){ - perror("pthread_mutex_init"); - exit(errno); - } -#endif - - if(_______(&tid1, NULL, thread_function, "thread1")!=0) { - perror("pthread_create"); - exit(1); - } - - if(_______(&tid2, NULL, thread_function, "thread2")!=0) { - perror("pthread_create"); - exit(1); - } - - if(_______(tid1, &thread_result)!=0) { - perror("pthread_join"); - exit(1); - } - if(_______(tid2, &thread_result)!=0) { - perror("pthread_join"); - exit(1); - } - -#ifndef NOMUTEX - ___________(&mutex_id); -#endif - - printf(" thread result : %s\n", (char *) thread_result); - return 0; -} - -void * thread_function(void * arg) -{ - int temp; - int i, j; - char buffer[80]; - - printf("thread_function called\n"); - for(i=0; i<8; i++) { -#ifndef NOMUTEX - _________(&mutex_id); -#endif - sprintf(buffer, "%s: CountRelay: from %d to ", (char*)arg, Counter); - write(1, buffer, strlen(buffer)); - - temp=Counter; - temp = temp+1; -// delay - for(j=0; j<5000000; j++); - - Counter=temp; - - sprintf(buffer, "%d\n", Counter); - write(1, buffer, strlen(buffer)); - -#ifndef NOMUTEX - __________(&mutex_id); -#endif - } - // getchar(); - _______("thread end"); -} diff --git a/08_12_thread/README.md b/08_12_thread/README.md index 87bd6b63fce3a697952614201b79472e5bf49198..bcd87e1f1f905c57e20aefc88bb6a8c27ff1a8cc 100644 --- a/08_12_thread/README.md +++ b/08_12_thread/README.md @@ -81,8 +81,11 @@ make 89 73 Main start! +====sthread1 start==== 합 : 1837, 평균 : 61.233334 +====sthread1 end==== Main end! +====sthread2 start==== 1등 : 100 2등 : 99 3등 : 96 @@ -113,7 +116,7 @@ Main end! 28등 : 9 29등 : 4 30등 : 1 +====sthread2 end==== ``` sthread2가 sthread1보다 연산량이 많아 늦게 끝나는 것을 볼 수 있다. -### 2.mymutexthread.c