linux pthread_suspend

后端 未结 5 2006
醉酒成梦
醉酒成梦 2021-02-08 03:36

Looks like linux doesnt implement pthread_suspend and continue, but I really need em.

I have tried cond_wait, but it is too slow. The work being threaded mostly execut

相关标签:
5条回答
  • 2021-02-08 03:42

    May be try an option of pthread_cancel but be careful if any locks to be released,Read the man page to identify cancel state

    0 讨论(0)
  • Have the threads block on a pipe read. Then dispatch the data through the pipe. The threads will awaken as a result of the arrival of the data they need to process. If the data is very large, just send a pointer through the pipe.

    If specific data needs to go to specific threads you need one pipe per thread. If any thread can process any data, then all threads can block on the same pipe and they will awaken round robin.

    0 讨论(0)
  • 2021-02-08 03:51

    Why do you care which thread does the work? It sounds like you designed yourself into a corner and now you need a trick to get yourself out of it. If you let whatever thread happened to already be running do the work, you wouldn't need this trick, and you would need fewer context switches as well.

    0 讨论(0)
  • 2021-02-08 04:01

    Make the thread wait for a specific signal.

    Use pthread_sigmask and sigwait.

    0 讨论(0)
  • 2021-02-08 04:01

    It seems to me that such a solution (that is, using "pthread_suspend" and "pthread_continue") is inevitably racy.

    An arbitrary amount of time can elapse between the worker thread finishing work and deciding to suspend itself, and the suspend actually happening. If the main thread decides during that time that that worker thread should be working again, the "continue" will have no effect and the worker thread will suspend itself regardless.

    (Note that this doesn't apply to methods of suspending that allow the "continue" to be queued, like the sigwait() and read() methods mentioned in other answers).

    0 讨论(0)
提交回复
热议问题