Search code examples
csleepblockingmulticast

Does sleep() block?


I am implementing a multi cast server that sends a message every X amount of seconds to a multicast address.

I am also part of the multicast group and I will also receive messages from other senders in that group.

My question is, can I use sleep(X) to send my message while still receiving other messages from the group and process them? Or does sleep() block?


Solution

  • Sleep blocks all execution, but only in the thread from which you call it. I would suggest that you create two threads, one for broadcasting and one for listening. Then make sure that you synchronize any data shared between the threads with Mutexes.