Thread Wait For Parent

后端 未结 5 416
一个人的身影
一个人的身影 2020-12-10 19:30

I am implementing a simple thread pool mechanism for my ubuntu server (for my multi-client anonymous chat program), and I need to make my worker threads sleep until a job (i

5条回答
  •  自闭症患者
    2020-12-10 19:34

    Since a network chat program is presumably I/O-bound rather than CPU-bound, you don't really need threads. You can handle all your I/O in a single thread using a facility such as Boost.Asio or the GLib main loop. These are portable abstractions over platform-specific functions that allow a program to block waiting for activity on any of a (potentially large) set of open files or sockets, and then wake up and respond promptly when activity occurs.

提交回复
热议问题