title: x number of threads sending data to Server for displaying output on GUI
body: <p>I have developed a single server/multiple client TCP Application.</p>
  
  <p>The client consists of x number of threads each thread doing processing on its own data and then sending the data over TCP socket to the Server for displaying.</p>
  
  <p>The Server is basically a GUI having a window. Server receves data from the client and displays it.</p>
  
  <p>Now, the problem is that since there are 40 threads inside the client and each thread wants to send data, how can I achieve this using one connected socket?</p>
  
  <p><strong>My Suggestion:</strong></p>
  
  <p>My approach was to create a data structure inside each of the 40 threads in which data to be sent will be maintained. A separate Send Thread with one connected socket on client side is then created. This thread will read data from data structure of first thread, send it over the socket and then read the data from second thread and so on. </p>
  
  <p><strong>Confusions:</strong></p>
  
  <p>but I am not sure how would this be implemented as I am new to all this? :( What if a thread is writing to data structure and the Send Thread tries to read the data at the same time. I am familiar with mutex, critical section etc but that sounds too complex for my simple application.</p>
  
  <p>Any other suggestions/comments other than my own suggestion are welcome.
  If you think my own approach is correct then please help me solving my confusions that I mentioned above.</p>
  
  <p>Thanks a lot in advance :)</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Can I put I timer on Send Thread and after a specific time the Send Thread suspends thread#1(so that it can access its data structure without any synchronization issues), reads data from its data structure, sends it over the tcp Socket, and resumes Thread#1 back, then it suspends Thread#2, reads data from its data structure, sends it over the tcp Socket, and resumes Thread#2 back and so on.</p>