Is there a way to wake a specific thread in Haskell? There is a function that suspends the current thread. But the waking counterpart doesn’t seem to exist.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
yielddoesn’t suspend the current thread – it moves it to the back of the run queue. It’s still in the run queue, it just makes sure that other runnable threads (potentially not all runnable threads, if there are multiple execution contexts defined, which makes this a a pretty weak guarantee) have a chance to run before it continues. For the most part, you should ignoreyield. The exception is when you understand exactly what it does, and why that matters.To actually suspend and resume a thread,
MVars are the way to go. When a thread waits on an emptyMVar, it is removed from the runnable queue. When a value is put into anMVar, a thread waiting on it (I believe in GHC it’s always the thread that has been waiting on thatMVarlongest, but it’s not guaranteed) is put back into the runnable queue.