Active Oldest Votes. Improve this answer. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Learn more. How to compile a C program that uses pthread. Ask Question. Asked 7 years, 9 months ago. Active 3 months ago. Viewed k times. Improve this question. Gabriel Staples 4, 3 3 gold badges 45 45 silver badges 70 70 bronze badges. Add a comment. Active Oldest Votes.
Use: gcc MyProgram. Nothing happens by default. The condition variable mechanism allows threads to suspend execution and relinquish the processor until some condition is true. A condition variable must always be associated with a mutex to avoid a race condition created by one thread preparing to wait and another thread which may signal the condition before the first thread actually waits on it resulting in a deadlock.
The thread will be perpetually waiting for a signal that is never sent. Any mutex can be used, there is no explicit link between the mutex and the condition variable. Everything else is random.
The logic conditions the "if" and "while" statements must be chosen to insure that the "signal" is executed if the "wait" is ever processed. Then I found some recommendations from the net so I tried gcc this time. Unfortunately, I got a bunch of errors after calling gcc myfile. The point is that I got these errors after I upgrade my softwares via sudo apt-get update -y. You are very confused about the difference between kernel code and application user-space code.
You should avoid writing kernel code. Read about CPU modes. Kernel code is for stuff like device drivers , not for Sudoku-s. Of course, you cannot use pthread in kernel code : the kernel is implementing threads by providing the clone 2 syscall to applications. Read ALP and intro 2 then intro Take several days to read some pthread tutorial. You'll probably need mutexes and conditional variables for synchronization. If you want to learn kernel programming, start with some much simpler task.
0コメント