semaphores in mutex replacing while loops
Ok two questions in this one.
1. Is it better to use semaphores in a mutex thread program rather than while loops? I have been looking at some tutorials online and would like a little light shed on the meaning of : wait(S1); C--; if (C < 0) { signal(S1); wait(S2); } signal(S1); wait(S1); C ++; if (C <= 0) signal(S2); else signal(S1); I know it has something to do with bool. but do I have to declare S1 or can I declare a different variable for S1 and have it still work? |
I figured out how to work with them and what it all means.
But my program is giving me the following error /tmp/ccejb4CZ.0(.text+0xcd): In function `main`: : undefinded reference to `thread_function` collect2: ld returned 1 exit status in the beginning of my code I defined it as follows void *thread_function(void *arg) I use it in the following line res = pthread_create(&a_thread, NULL, thread_function, NULL); and again at the end of my code int main() { } void *thread_function(void *arg) { sem_wait(&bin_sem); while(strncmp("end", work_area, 3) != 0) { printf("You input %d characters\n", strlen(work_area) -1); sem_wait(&bin_sem); } Can someone please explain to me this error? |
All times are GMT -5. The time now is 05:13 AM. |