Does a data race only occur with a segfault?

My packets get corrupted with bad values over time. Not necessarily going over the packet size.

Just to be assured because I have this feeling that this may be weird, but my code does not segfault (It would if I let the code access the garbage input, but my asserts and range checks always catches it).

Does this mean the problem is not a data race? I am confident that my current system is a bit careless with mutexes (i just threw some mutexes into the global scope at first and it kinda worked).

(not showing the my code because I just want assurance, and the code is too long)
Data races are not related to segfaults.

Although I could envision a situation where a data race could produce a wild pointer or an out-of-bounds index, it's like saying "does integer overflow only occur with a segfault?"
I always thought that the action of 2 threads interfering with each other would cause a segment fault, are there no cases that would happen at the very instance a value is modified?

(or maybe I was reading gdb wrong, I find it rare to be able to be able to find what the other threads are doing other than waiting, then again maybe I am delusional!)
Last edited on
When writing threaded code it's more important than ever to know what you're doing. Just writing something and see if it works without thinking it through will inevitably lead to buggy programs.

That said, some compilers has special flags that help you detect data races (e.g. -fsanitize=thread in GCC and Clang).
I always thought that the action of 2 threads interfering with each other would cause a segment fault, are there no cases that would happen at the very instance a value is modified?


segFault happens when you try to read or write memory that the OS thinks you shouldn't be. Nothing at all to do with threads.

... that would happen at the very instance a value is modified?

That's always when a segFualt happens. When you modify (or read) the variable. Be a bit silly if the segFault could happen before you try to read the variable.
Topic archived. No new replies allowed.