I have the following scenario:
The program has a reader and a writer thread to a socket which is an external application.
The reader and writer need to work in coordinated cycles.
The writer sends a dynamic number of messages (x) to the socket and the reader needs to read the responses from the socket. The number of messages is over 5 to 10k per cycle. The messages are not received in the same order as sent and the message have a clear layout, so it is possible to determine single messages.
The reader needs to read x messages and perform then some processing after the . The writer needs to restart sending to the socket after the reader has performed the after-reading processing.
What is the fastest synchronisation from your pov?
- Sending a special message to the socket with the number of written messages? (Even though there is no FIFO guarantee on the socket)
- Work with the classical locking object?
Use atomic-transactions for integers with the number of written messages and let the writer update the integer only once?
Have I missed any other fast synchronizing mechanism?