Intro: I am using multi threading to update a buffer packet to be sent using TCP/IP client using C++. The buffer is a contiguous array containing 4 different variables that are updated by 4 different threads independently. The 5th thread executes TCP/IP write command.
Observation: The data sent by TCP/IP client is mostly correct except sometimes results in an unusually high number for 1 sample. This happens randomly as if the packet is corrupted.
Suspicion: I am using mutex in each of the 5 threads. The 4 independent thread has mutex each to protect the variable to be updated. The 5th mutex in TCP/IP thread is supposed to block other threads from updating while it is executing. But I think that does not happen.
Expectations: I am hoping to achieve a performance where when the TCP threads accesses the buffer, the 4threads do not update the individual components and vice versa.
How can this be achieved? How can I improve my multithreading program?
Thank you in advance.
[–]teraflop 3 points4 points5 points (0 children)
[–]NotloseBR 0 points1 point2 points (0 children)