Valgrind stalls in multithreaded socket program

I am running a multi-threaded socket program with valgrind. The client will send a request to the server via TCP, and then busy waiting at the logical level. A boolean value will be set when the callback function that serves the response from the server is called. After receiving the response (and the boolean flag is set), the server will again send the request and do it again in a loop.

I understand that unchecked access to shared variables (logical) can cause problems with threads, but I tried to use pthread mutexes, and the program slows down by about 20% (speed is important here). I am sure that writing to a shared boolean is fine, as it can be done in a single loop.

The program works fine outside of valgrind, but often stops when it starts with valgrind. I left the program to run overnight. It usually takes only a few seconds to complete, so I don’t think this is the case when you do not wait long enough for the program to end. Thread management is done using the open source framework (quick fix), so I don't think this is a problem with thread creation / management.

Does anyone know of any problems with valgrind around multi-threaded programs / busy waiting / socket communication cycles (or a combination thereof)?

+5
source share
3 answers

, (-, ), , Valgrind.

, Valgrind . , Valgrind , .

Valgrind, , , , , .

, , , , Valgrind, . , , , , .

, , , . .

.

+6

/ - x86.

. : volatile C/++?

+3

Even if the logical element record is an atomic operation, the compiler and processor can re-order the update around other memory accesses. Your busy stream may wake up from a busy cycle and discover that the shared data structure has not yet been updated.

I highly recommend sticking with the available typing primitives to write sequential programs that execute exactly the way you want, each time.

+2
source

All Articles