CodePudding user response:
Saw your problem, use a multi-threaded or thread pool is not the key to realize the function, you server that produce data while sending data, should be the typical producer consumer model, so the problem is transferred to the model, can find some solution to handle the pattern to the net, there are a lot of, there is always a suitable for you,CodePudding user response:
Look at your choiceCodePudding user response:
Mutual exclusion can be finished through the semaphoreCodePudding user response:
1. If from efficiency consideration, this kind of circumstance is not recommended to open a thread, you can directly in the main program data will be sent to the corresponding client, it has better real-time performance,2. So to consider, the server to start, after listening to a port, after client connection, to have the data server, invoke sendto directly sent to the client,
In so doing, both in efficiency and real-time performance is good,
CodePudding user response: