weismat
weismat

Reputation: 7411

Fastest synchronisation

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?

Upvotes: 3

Views: 478

Answers (1)

Gabe
Gabe

Reputation: 86718

Unless you are doing this on the order of 100,000 times per second, it doesn't really matter which mechanism is microseconds faster than another. Just use whatever mechanism is the easiest to understand and/or get working. Then only consider optimizing the mechanism if it turns out to not be fast enough. More than likely the message processing itself will use several orders of magnitude more time than this synchronization.

Upvotes: 3

Related Questions