Yes, you can call accept() on the same listening socket from multiple threads and multiple processes, although it may not make as much sense as you think. The core will only allow success. When this is done with processes, this is called preforking, and it saves fork() for every new connection. But when dealing with threads, you can easily have an existing thread pool that is waiting for a queue of new connections. One thread executes accept and writes the queue, and worker threads read the queue and do their work. Itโs cleaner, itโs a well-understood drawing, and you lose almost nothing.
source share