6 ms·
But many race conditions are harmless. 'Fixing' those that are with extra synchronisation is not a good use of anyone's time.
by chrisseaton 7y ago
But many race conditions are harmless. 'Fixing' those that are with extra synchronisation is not a good use of anyone's time.
- ggggtez 7y agoI think by definition, you are wrong. If the race condition was harmless then it wouldn't be a race condition.
- chrisseaton 7y agoBy who's definition? If you go by Padua's classic definition, it's any behaviour that depends on timing sequences. For example HN has a race condition in that the ID your comment gets allocated depends on when it's submitted. But that's not a bug, is it? It only becomes a bug when it's undesirable. I think, like a few people here, you're confusing it with a 'data race'.
- mffnbs 7y agoYou still understand, though, that the colloquial definition being used here is what you're referring to as a "data race." Your comments are disingenuous in that I believe you know that you're being pedantic, I just don't know why you've brought it up the multiple times.
- chrisseaton 7y agoI didn't realise something as specific as 'race condition' could have a colloquial definition, but ok.
- pure-awesome 7y agoFor many terms of (programming) jargon, there's a strict academic definition, perhaps as defined in a paper in which the term was originally introduced, and the usage of the word in the broader (programming) community. The latter is the colloquial definition.
- tanr54ok 7y agowhat? You need to describe what you’re saying better. How is an ID allocated a comment a “race condition”. A race condition desirable or not has to be related to some sequence of events.. ie its a race with a particular set of outcomes. What you’re describing sounds like basic cause and effect.
- chrisseaton 7y agoEvent A is your comment. Event B is my comment. If your comment gets to the server first if gets ID 1. If mine gets to the server first it gets ID 1. Which ID you get depends on timing outside your control. They race to get the ID. A race condition.
- tanr54ok 7y agoSo what? What’s missing is that unless something depends on the ordering of those ids, it really isn’t a race condition. Just plain happening of events is the inevitable passage of time, not a race condition. What is interesting about what happens downstream with those IDs? You’re not wrong that not all race conditions are harmful, but i feel you’re doing a pretty bad job of explaining what a race condition is.
- zzzcpan 7y agoDidn't we go over this already? It's not any behavior that depends on timing sequences, it's only if your code assumes it can rely on timing sequences while it can't, i.e. a bug.
- chrisseaton 7y ago> It's not any behavior that depends on timing sequences, That's literally how 'race condition' is defined in the industry.
- zzzcpan 7y agoNot true, it's pretty hard to encounter anyone in the industry using the phrase "race condition" without implying a bug.
- ggggtez 7y agoI feel like this comment is a classic example of reading a wikipedia entry instead of understanding the topic. You can use it to refer to any race, but in reality the race you are referring to is only subjective to the user. The server is generally processing all requests in the order they are received. A race condition usually is referring to a multithreaded system where the threads interfere with each other, causing undesired effects. Relaxing "race condition" to refer to all causality... is such a loose definition as to give it no meaning at all.
- chrisseaton 7y ago> I feel like this comment is a classic example of reading a wikipedia entry instead of understanding the topic I did a PhD partially on irregular parallelism where understanding race conditions are essential for understanding the topic.
- hunter2_ 7y agoThe phrase "race condition" is usually not used to describe the harmless asynchronous code you're referring to.
- chrisseaton 7y agoNo you're thinking about 'data races'. Almost all software that interacts with the outside world, or clocks, like of course a kernel, is going to have many harmless 'race conditions'. Erlang for example, is a language extremely prone to race conditions, but not to data races.
- tsbinz 7y agoThe tool specifically looks for data races.
- dekhn 7y agoI've never heard the term "race condition" refer to something that was harmless. Can you point to some examples in the literature?
- chrisseaton 7y agoEven Wikipedia says it's not always a bug > A race condition or race hazard is the condition of an electronics, software, or other system where the system's substantive behavior is dependent on the sequence or timing of other uncontrollable events. It becomes a bug when one or more of the possible behaviors is undesirable. Or read the canonical Encyclopaedia of Parallel Computing page 1693 > [A race condition is when there is] some order among events [where the] order is not determined by the program
- petschge 7y agoRandom imagined example: Two files with different names being created in the same directory. The race decides which one gets which inode number, but both are created correctly and successfully. That would be a race condition, but as long as only the assignment of inode numbers changes between outcomes of the race nobody would care. But again, this is just a contrived example.
- shaklee3 7y agoSome race conditions are intentional at the expense of knowing that the data would not be perfect. For example, if you have a structure of different metrics and one thread updates them while another thread reads them, clearly the best way to handle that is to lock while writing and reading so you always get the intended results. However, if you don't necessarily care about all of your metrics being snapshotted at the exact same point in time, you can just have the other thread share the variables knowing that this race condition will actually improve performance a little bit. Obviously you need to take care of things like words sizes that take multiple loads and stores.
- dekhn 7y agoHmm. I thought data races due to concurrent thread access are actually undefined behavior (up to and included termination of the program).
- sanxiyn 7y agoNote that Phoronix is being imprecise here and those hundreds are in fact data races (with no false positives), which are never okay.
- chrisseaton 7y ago> data races (with no false positives), which are never okay This just isn’t true. Here’s a concrete example - many JIT compilers use counters to work out when to compile a method. They allow data races in updates to the counters because performance is more important than correctness for them and the impact of a lost write is basically zero. It’s only a bug if you decide it’s a bug.
- gpderetta 7y agoby definition data races in C and C++ are UB. Even if you believe that the compiler cannot not possibly miscompile your code [1], a large quantity of these false positives will make data race detection tools (like the one used by G) less useful. Just mark your shared memory locations as atomic, you can always use relaxed ordering and non-atomic RMW operations if you worry about the cost of the extra synchronization. [1] these sort of assumptions of course tend not to age well.
- chrisseaton 7y agoData races are. Race conditions are not.
- gpderetta 7y agoTrue.