Hey,
I have a number of threads running which create a class that uses a socket to connect to a TCP server. A new instance of the socket connecting to the same IP and Port is created each time a object is created.
Heres how it goes:
- 10 threads are spawned each creating a new instance of my class
- Class creates a new socket (new Socket("host", port))
- The class gets a unique key from the server upon connecting
- The class then uses that unique key to generate a hash
All good up till this point
- I would expect for the thread to send back the hash to the server right away. However, the second thread for some reason creates a new socket and repeats the process above before the 1st thread finished.
- When all 10 threads have finished generating their hash it goes back to the 1st thread which then begins to start sending its hash back to the server. I do not want this to happen, because, well... it invalidates the valid hash it previous generated.
How can I make sure it sends the hash back to the server before any other threads can request one?
I have zero control over the thread creation code.
Thanks,
Tom