News for hackers. Stuff that matters.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by dekhn on Thursday October 03, 2019 @09:35AM (#21146760)
"brakes make my car slower, so I'd expect my average velocity to decrease if you fixed them"
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by mindcrime on Thursday October 03, 2019 @11:54AM (#21148425)
"brakes make my car slower, so I'd expect my average velocity to decrease if you fixed them"

Just to be pedantic... in some contexts better brakes actually allow you to go faster. Consider racing on an oval track... a car with better braking ability can maintain speed longer as it approaches a corner, then scrub off speed more quickly to navigate the corner. A car with inferior brakes has to start slowing down sooner or risk crashing by taking the corner too fast. So better brakes can lead directly to faster lap times.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by magduf on Thursday October 10, 2019 @09:26AM (#21214112)
>Just to be pedantic... in some contexts better brakes actually allow you to go faster.

Yes, and in other contexts, better brakes make you go slower. Better brakes means bigger brakes: larger rotors (discs), larger and heavier calipers, etc. Larger brake rotors take more energy to accelerate (they're basically a bigger flywheel), so they decrease the car's acceleration. So if your goal is to have a car that accelerates as fast as possible, better brakes are actually a big detriment.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by nickserv on Thursday October 03, 2019 @01:12PM (#21149288)
Indeed, disk brakes were first used on race tracks before being available on street cars.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by discreteevent on Thursday October 03, 2019 @02:59PM (#21150733)
And some people now argue that disc brakes on road bicycles are more dangerous because you learn that you can brake later and more suddenly. I.e You will more frequently approach the limit of friction between the (very narrow) tyre and the road.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by magduf on Thursday October 10, 2019 @09:28AM (#21214155)
>And some people now argue that disc brakes on road bicycles are more dangerous

Some people argue that the Earth is flat. That doesn't mean they have a good point.

The morons you're referencing probably think cars should all go back to drum brakes and bias-ply tires so people think more about brake fade and tire grip. It's an idiotic argument. Disc brakes on bikes are better in every way, except weight (they add about 1 pound, maybe). Reducing performance available to a cyclist doesn't make any sense at all; you never know when you're going to need to stop suddenly in the real world.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by mindcrime on Thursday October 03, 2019 @03:40PM (#21151203)
I had not heard that one. I always thought the main argument against disc brakes on road bikes was they they aren't good for long descents where you're riding the brake for long periods of time... due to heat fade or whatever.

Of course both things could be true...

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by magduf on Thursday October 10, 2019 @09:31AM (#21214185)
>I always thought the main argument against disc brakes on road bikes was they they aren't good for long descents where you're riding the brake for long periods of time... due to heat fade or whatever.

No, you have it the other way around. Rubber brake pads on wheel rims fade with heat; disc brakes are able to dissipate far more heat, and are basically essential for long descents.

The only valid argument against disc brakes on bikes is that they weigh a little more (maybe 1 pound). I suppose you could also argue that brake fluid is more trouble to deal with than a cable, and certainly not as easy to jerry-rig, but hundreds of millions of cars use hydraulic brakes without any trouble these days, and I wouldn't want to have jerry-rigged brakes anyway.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by mhh__ on Thursday October 03, 2019 @02:36PM (#21150400)
Indeed. The insane thing about a modern F1 or LMP1 car isn't the acceleration (or at least not as much, the hybrid systems in a modern x car change that) but the braking.

Some drivers have complained about rain because the tears have been literally pulled out of them under the deceleration

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by loeg on Thursday October 03, 2019 @02:59PM (#21150725)
I think dekhn may be making the same point, so no need for "Just to be pedantic." You raise an interesting factoid that many people probably haven't thought about, although it's pretty easy to intuit once you are encouraged to think about it.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by dekhn on Friday October 04, 2019 @08:55AM (#21157132)
No I wasn't making that point. The side-pedants talking about racing cars, those represent a tiny amount of braking activity compared to the total amount of braking activity across the world, so my statement about expecting the average velocity to go down still stands.

Also, I drift corners instead of braking, it seems to be a lot faster if you nail the tire orientation on the exit.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by mindcrime on Friday October 04, 2019 @10:51AM (#21158272)
Also, I drift corners instead of braking, it seems to be a lot faster if you nail the tire orientation on the exit.

Fair point. As the old saying goes "looser is faster". The risk, of course, is that you wind up in the wall with your velocity = 0. :-)

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by X6S1x6Okd1st on Thursday October 03, 2019 @03:07PM (#21150824)
In factorio the research you perform to get your trains to run faster is braking force research.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by Craighead on Thursday October 03, 2019 @11:56AM (#21148449)
That helps that posters arguments.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by mindcrime on Thursday October 03, 2019 @12:07PM (#21148586)
That's fine by me. I don't have a dog in that fight, so to speak...
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by babuskov on Thursday October 03, 2019 @09:39AM (#21146795)
It's more like traffic lights being turned off.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by vanderZwan on Thursday October 03, 2019 @10:33AM (#21147429)
I grew up near a city where they set up the traffic lights along one of the main roads in such a way that if you kept to the speed limit you would always arrive at the next light just after it turned green, so you never would have to brake or accelerate. I wouldn't be surprised if there are concurrency patterns analogous to that.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by Fnoord on Thursday October 03, 2019 @10:42AM (#21147551)
Ah yeah, groene golf (green wave [1]). I grew up remembering my parents also using that. Except it never bloody worked.

[1] https://en.wikipedia.org/wiki/Green_wave

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by devicetray0 on Thursday October 03, 2019 @10:59AM (#21147790)
Wow, from that article:

> In the UK, in 2009, it was revealed that the Department for Transport had previously discouraged green waves as they reduced fuel usage, and thus less revenue was raised from fuel taxes.

Ugh...

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by vonmoltke on Thursday October 03, 2019 @12:56PM (#21149101)
Perverse behaviors like this are what make we worry about the calls to tax negative externalities without earmarking the funds for addressing those externalities. If you tax the externalities, but get to use the revenue for something else, what is your incentive to reduce the behavior causing the problems in the first place?
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by aeorgnoieang on Thursday October 03, 2019 @02:15PM (#21150080)
Yes! This is a point I raise frequently. My go-to example is cigarette taxes being used to fund public schools. They should be used to cover costs (borne by the relevant government) of people smoking cigarettes! Otherwise, as has happened, school funding can be hurt by people smoking less, which is not a good situation to have created.

The degree by which governments routinely violate the accounting principle of matching revenues to expenses is awful.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by loeg on Thursday October 03, 2019 @03:01PM (#21150750)
I think you're describing the problem of earmarking funds at all. In general it's just a stupid posturing maneuver. Spending is fungible; it just replaces the amount contributed from the legal body's general fund. As needs change, general fund money can be spent as needed. Earmarked funds are stuck.

A carbon tax on consumers (incl. businesses) is effective at producing good market behavior regardless of how the tax revenue is spent.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by vonmoltke on Thursday October 03, 2019 @03:19PM (#21150950)
> A carbon tax on consumers (incl. businesses) is effective at producing good market behavior regardless of how the tax revenue is spent.

In the example I reacted to, a government agency actively worked to inhibit that behavior in order to preserve its revenue. Your point would hold if governments didn't have the power to do things like this.

> Earmarked funds are stuck.

If the revenue is being raised to pay for damage caused by society, those funds should be stuck to that purpose and should rise and fall based on the level of damage being done.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by loeg on Thursday October 03, 2019 @07:33PM (#21153367)
> In the example I reacted to, a government agency actively worked to inhibit that behavior in order to preserve its revenue. Your point would hold if governments didn't have the power to do things like this.

A governmental bad actor is basically orthogonal to the idea of a carbon tax. The government could equally try to increase sales of liquor and cigarettes for sin taxes, or go around murdering people for the estate taxes. The UK example is shameful but reflects on that government body rather than the specific tax on petrol.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by thomasz on Friday October 04, 2019 @08:08AM (#21156757)
This is very likely an urban myth.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by aeorgnoieang on Friday October 04, 2019 @11:46AM (#21158798)
The problem isn't earmarking funds in general. Money has to be allocated somehow and it's good to do so explicitly.

The problem is earmarking or allocating a variable set of revenue as funding for something unrelated, and in particular something unrelated that's otherwise valuable or important.

And NOT earmarking or allocating 'sin taxes' to pay for the supposed costs of those sins, borne by the public in the form of the government, seems pretty stupid (to me) if it's actually necessary or desirable for the government to 'manage' those sins or those sin's consequences.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by red75prime on Friday October 04, 2019 @03:10AM (#21155487)
Ave, Government, morituri te financiert.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by smolder on Thursday October 03, 2019 @11:38AM (#21148228)
It makes me really disappointed in the world every time I hear stories like this. Supposedly we chose 110v power over a higher voltage in the US so we could sell more copper in wires. And everyone can see Health Care is a two-faced profiteer-filled industry here.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by philjohn on Thursday October 03, 2019 @12:06PM (#21148578)
Yes - but smart motorways are doing a pretty good job of handling congestion at peak times by keeping traffic moving at a slower pace, which ends up with everyone using less fuel ... so at least UK roads are becoming slightly better in that regard :)
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by KirinDave on Thursday October 03, 2019 @11:50AM (#21148380)
Yes, well, the green wave is a good idea in principle, but it's sorta mistaking averages for reality.

There is this thing called the "waiting time paradox" [0] (or more generally the "inspection paradox") that suggests a surprising thing, the average time between discrete events observed by many other randomly interspersed observation is the same as the average time between events. This should be surprising, because it suggests that many more people experience times LONGER than the average wait to balance out people who experience a shorter wait because they were randomly closer to the event.

This happens because longer intervals, when they do exist, get a larger proportion of the random observations than the shorter intervals between events. More precisely and generically, when the quantity being observed affects the observer, the observations will be distorted by the quantity in question and have to be normalized.

In the case of a green wave, those rare times when someone waits too long on a green because they were looking at their phone or a naked person in a nearby window and create slowdowns and stalls in the pipeline? Those moments are longer, so there is a longer window where you could experience them.

This actually comes up a lot in observations of things in nature. Imagine if instead of light flips or bus arrivals we were observing clicks on a geiger counter and you'll realize how fundamental this is to experiencing the world.

tl;dr: The Green Wave only works in averages and it can be correct even as your experience of it never working is also correct. :)

[0]: https://jakevdp.github.io/blog/2018/09/13/waiting-time-parad...

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by mmjaa on Thursday October 03, 2019 @11:18AM (#21148014)
Here in Vienna, it works great. Its often quite amusing to me, as I ride a slow moped - about horse speed - and get passed by irate drivers all the time. However, I ride that green wave, while they are constantly stopping/starting at the lights ...
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by babuskov on Thursday October 03, 2019 @10:54AM (#21147716)
Works fine in my town (population around 100k). 50kmph (around 31mph) and it's all green for some 20+ crossroads.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by jandrese on Thursday October 03, 2019 @02:08PM (#21149995)
There is a road near where I used to live that was the opposite. Speed about 10mph over the limit (55 in a 45) and it would be green all the way. Go the speed limit and you get stopped at every single light. It was shockingly reliable. The difference between speeding and going the speed limit was 15 minutes on a 20 minute drive. The only time it got broken up was the one intersection with a pedestrian crosswalk where people sometimes hit the button.

Of course traffic was heavy enough that you'd be stuck behind someone doing the speed limit most days, but sometimes you got to ride the wave.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by perl4ever on Thursday October 03, 2019 @11:17PM (#21154496)
As I wrote in another post, there's a highway near me where you almost always hit every red light, but it's designed such that going say 20% over the limit won't work either. I believe some people deliberately go 20% under to reduce the waiting.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by jsgo on Thursday October 03, 2019 @01:34PM (#21149587)
I'd be willing to give that a shot; I drive the speed limit in my town (population estimated at about 15.6k), but the lights seem more in relation to current traffic at the intersection. So you catch this red light and you're going straight, you stop and wait. Now when you approach the second light, because you and others were held back there was no one approaching the light so it will likely be red or turning red when you approach. To actually get out of this loop, you basically have to speed up a bit which seems like a behavior that shouldn't be rewarded as such.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by mikestew on Thursday October 03, 2019 @01:57PM (#21149848)
Sounds like sensor-based lights and not timed lights? Regardless, Redmond, WA is full of sensor-based lights. Hence I catch myself speeding up to an otherwise empty lane and a green light. 'cuz if I don't hurry up, it'll turn red.

Timed lights work, I've seen it in action. Top of my head, Indianapolis 20 some years ago, Capitol Avenue going north I'd bet you could go from (what is effectively) Zero Street to 38th and not hit a red light.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by vanderZwan on Thursday October 03, 2019 @10:53AM (#21147696)
Worked fine for my family near Drachten, but that had the advantage that they also had a sign showing your speed next to the road. I suspect one issue is that the speedometer in cars are not that accurate
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by SECProto on Thursday October 03, 2019 @03:05PM (#21150797)
I live somewhere with lots of roadside speed signs (they flash speed in red if you're speeding, green if under). In the tens of cars I've driven/ridden here, the speedometer is always within a small range (±2km) of what the road sign says
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by vanderZwan on Saturday October 05, 2019 @08:51AM (#21165223)
The thing is that you have to look at this from the perspective of the expected largest difference between different cars, not one speedometer and actual speed.

If two cars both say they drive at 50 km/h, and one is actually 45 km/h and the other 55 km/h, that is quite a bit relative margin of error. And we only need two cars like that in the whole group to start causing problems.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by SECProto on Saturday October 05, 2019 @10:08PM (#21169369)
But I don't think you have to look that hard at some technical error causing this variance. Drivers speeds vary between 40 and 60 pretty regularly on residential roads. Having a speedometer error doesn't even have to enter into the conversation.

If you can't design a green wave to be tolerant of varying speeds, then it isn't useful.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by perl4ever on Thursday October 03, 2019 @11:20PM (#21154504)
There are some weird speed signs near me. One that particularly irritates me is set up to flash if you're over 25 mph. But the speed limit is 30! There's also a flashing sign by a school, that is left on at times that the regular sign specifically says the school speed limit is not in effect.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by kevin_thibedeau on Thursday October 03, 2019 @04:32PM (#21151849)
radar detectors always read lower than your true speed since they can't be positioned directly in your line of travel.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by SECProto on Thursday October 03, 2019 @06:22PM (#21152888)
In the situation I experience on my commute daily: I'm 40m back and the detector is 3m perpendicular off my line of travel (reasonable approximation, as they're on a roadside light standard, the lane width is 3.5m, and the car is centered in the lane), that is a very minor discrepency. On the order of 0.2 km/h
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by dekhn on Thursday October 03, 2019 @10:35AM (#21147463)
systolic matrix multiplication is roughly analogous to that.

Great Highway in SF, if you drive 35MPH you will just get greens on the evenly spaced lights. The worst is when you get stuck behind a person who drives 40, then brakes heavily, then drives 40, then brakes heavily, etc.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by svnpenn on Thursday October 03, 2019 @01:27PM (#21149493)
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by hawski on Thursday October 03, 2019 @11:50AM (#21148383)
There's a road in Berlin (and probably it's not an exception) that has overhead displays showing how fast you should go to be on a green wave. At least that's how I understood how it works from driving there several times. Additionally it has variable number of lanes for each direction signaled by lights.

Here it's street view of the road, it's not perfectly visible, because those are LED displays: https://goo.gl/maps/T7RzQCUS4nk3QVZN9

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by perl4ever on Thursday October 03, 2019 @11:13PM (#21154478)
There's a highway near me with periodic lights triggered by the cross traffic such that you almost always have to stop. The limit is 55 mph, but if you see someone on the side street and speed up to, say 70, to try to beat the light, you will probably see it turn yellow within a second and have to stop anyway. There aren't that many lights, but you almost always have to stop for every one because of the cross traffic taking precedence.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by Doubl on Thursday October 03, 2019 @10:41AM (#21147534)
Slow drivers must cause extreme road rage on that road
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by IggleSniggle on Thursday October 03, 2019 @11:20AM (#21148036)
In my experience, it is the “fast” drivers that cause road rage by being slow. They race to the next light, stop, and because they are stopped, prevent everyone from riding the green wave because they now must accelerate from stopped. Sooooo frustrating. Just go the speed limit and none of us will need to stop you idiots!

Edit: (or go double the speed limit if you must but please stop creating stops)

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by philjohn on Thursday October 03, 2019 @11:56AM (#21148450)
You run the risk of the computational equivalent of speedo not beeing 100% accurate, e.g. clock innacuracy.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by V-eHGsd_ on Thursday October 03, 2019 @11:15AM (#21147990)
there's a 3 or 4 mile stretch of road in san francisco called the great highway that's like this (https://www.google.com/maps/@37.750302,-122.5062241,14.64z)

It was one my little pleasures to drive along that at 35 (or 30, I forget what the speed limit was) and see cars zip ahead at each light at 45, only to watch them ride the brakes as they hit the next red.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by guan on Thursday October 03, 2019 @03:22PM (#21150981)
When there’s not too much traffic, Ocean Parkway in Brooklyn also has a green wave.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by smolder on Thursday October 03, 2019 @11:34AM (#21148184)
They did this on a few roads around where I grew up.(Southern Tier of New York.)
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by nashequilibrium on Thursday October 03, 2019 @10:52AM (#21147677)
The road I take to the gym is exactly like this, if you keep just under 40mph.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by swebs on Thursday October 03, 2019 @11:02AM (#21147841)
In both directions? How would that work?
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by ninkendo on Thursday October 03, 2019 @11:19AM (#21148024)
You can actually do all 4 directions.

Imagine a translucent checker board of blue and black squares overlaid on top of a map of roads. You can see the color of the squares but you can also see the roads underneath them.

If a light falls on a blue square, make its principal north/south direction Red at t=0 and it’s principal east/west direction green. For black squares do the opposite.

Calculate how long it would take cars to travel through each square unimpeded. It helps if this time is roughly the same regardless of direction. It also helps if the squares are roughly large enough that it takes roughly one light phase worth of time to travel through it. Call that time N.

At t=N, switch the lights to the opposite color, so now north/southbound traffic gets green lights on blue squares, and east/west gets red. Black squares get the opposite.

What you’ll see if you imagine yourself as a car driving through this, is that as you enter a black square as it turns green, the green lights will stay green until you enter the nearest blue square, at which point the phase shifts and now the blue square gets green lights as you drive through it.

This works in both directions, with both north and south bound traffic.

Now, this falls apart when roads are diagonal, although it’s mitigated if diagonal roads have higher speed limits. It also means if you make a turn, you’re in the wrong light cycle, but it will correct itself after the next red light.

It also doesn’t work well at all if you have left turn arrows complicating your light cycles, so you’ll need to have something like a Michigan Left and the requisite wide medians to make this work.

It’s not as ideal as I described in real life, but the basic principle works.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by cameronh90 on Thursday October 03, 2019 @11:58AM (#21148479)
I'm guessing it doesn't work so well if the stretches of road between lights are of significantly different distances.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by AnimalMuppet on Thursday October 03, 2019 @02:52PM (#21150632)
Or, worse, if the roads aren't on a rectangular grid. But for square blocks, it can work very well.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by PyroLagus on Thursday October 03, 2019 @02:18PM (#21150125)
So lock-free datastructures such as ring buffers are like roundabouts, huh?
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by curlypaul924 on Thursday October 03, 2019 @10:09AM (#21147112)
I see your point, though in racing brakes make a car faster, not slower. :)
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by LeonM on Thursday October 03, 2019 @10:22AM (#21147274)
Brakes slow a car down in terms of velocity over time. But they may make a car faster in the sense of distance over time (aka lap times).

I guess the real issue here is that 'fast' is ambiguous. In terms of racing it can be used for both lap-times or velocity. lap-times and maximum velocity are not necessarily correlated.

</nerdsnipe>

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by michalf6 on Thursday October 03, 2019 @10:34AM (#21147452)
You could say that brakes make the car faster in race conditions.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by IggleSniggle on Thursday October 03, 2019 @11:24AM (#21148069)
Daaaaaaaymn. Good one, holds up!
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by JangoSteve on Thursday October 03, 2019 @03:12PM (#21150876)
They often are correlated though. Better brakes mean you can stay on the accelerator longer before braking, which means you usually have higher maximum velocity and faster lap times (faster lap times are literally higher average velocities, so this makes sense).
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by resters on Thursday October 03, 2019 @10:57AM (#21147767)
Not really, if the brakes are broken, your average will approach 0 mph after the vehicle crashes.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by tryauuum on Thursday October 03, 2019 @12:53PM (#21149071)
Why are you comparing linux kernel and cars?
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by sxv on Thursday October 03, 2019 @01:27PM (#21149497)
Because analogy is the foundation of understanding things?
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by mikestew on Thursday October 03, 2019 @01:58PM (#21149866)
So, so far away from the glory days of Slashdot where it wouldn't even be considered a legitimate comment without a car analogy.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by chrisseaton on Thursday October 03, 2019 @09:41AM (#21146809)
But many race conditions are harmless. 'Fixing' those that are with extra synchronisation is not a good use of anyone's time.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by gpderetta on Thursday October 03, 2019 @12:17PM (#21148678)
by 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.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by chrisseaton on Friday October 04, 2019 @08:08AM (#21156765)
Data races are. Race conditions are not.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by gpderetta on Friday October 04, 2019 @12:59PM (#21159590)
True.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by sanxiyn on Thursday October 03, 2019 @10:11AM (#21147136)
Note that Phoronix is being imprecise here and those hundreds are in fact data races (with no false positives), which are never okay.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by chrisseaton on Friday October 04, 2019 @05:56AM (#21156199)
> 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.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by dekhn on Thursday October 03, 2019 @10:07AM (#21147092)
I've never heard the term "race condition" refer to something that was harmless. Can you point to some examples in the literature?
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by chrisseaton on Thursday October 03, 2019 @10:11AM (#21147127)
Even 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

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by shaklee3 on Thursday October 03, 2019 @10:55AM (#21147733)
Some 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.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by dekhn on Thursday October 03, 2019 @11:16AM (#21147999)
Hmm. I thought data races due to concurrent thread access are actually undefined behavior (up to and included termination of the program).
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by schoen on Thursday October 03, 2019 @12:29PM (#21148813)
Are you thinking of a particular programming language specification here? It seems like one programming language might define this this way, while another might simply say that the order of the events is not guaranteed (and may not be the one that the programmer expected), but not that the events themselves may do something other than the normal language semantics provide.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by jcranmer on Thursday October 03, 2019 @02:14PM (#21150072)
C++ and C both explicitly say that data races are undefined behavior, not unspecified behavior.

Data races are one of those cases where "anything may go" undefined behavior is actually quite necessary. Actual hardware memory models (particularly on "weak" architectures like ARM or PowerPC, or especially the infamously weak Alpha) result in cases where the order of memory traffic is not a consistent view between different threads. Formally specifying the hardware memory model is actually surprisingly difficult, made all the more difficult when you want to give a hardware-agnostic definition [1]. And should you want to introduce hardware transactional memory, break down in despair at the complexity [2].

The great breakthrough in memory models is the definition of the "data-race-free" model. This model says that, if memory accesses are properly protected with locks (i.e., there are no "data races" [3]), you cannot observe a violation of sequential consistency, which makes reasoning much easier. Java used this model for its corrected memory model in Java 5, and then C++11 adapted Java's memory model, and C11 took C++11's model verbatim. The upshot of this approach is that, if you make data races undefined behavior, you don't have to try to figure out how typical memory optimizations, both by the compiler and by the physical hardware, affect visible memory. Trying to work out the effects of these optimizations on the memory system is extraordinarily difficult, and the benefits of doing so are manifestly unclear, since most programmers will need to properly synchronize their code anyways.

[1] The C++ memory model attempts to do this with atomic memory references. The resulting specification (in C++11) is generally considered to be wrong, and the question of how to fix it is still up in the air as of right now.

[2] PLDI 2018 had the first formal semantics that combined transactional memory and weak memory semantics, and went on to prove that ARM's hardware lock elision was broken. This should be showing just how difficult this is to grasp even for theoreticians pushing the boundary, let alone a language trying to make it accessible to typical programmers.

[3] There are two definitions of "data race" going on here. Vernacular definitions usually define it as accesses not protected by synchronization, which permit "benign" data races for regular loads/stores. C/C++ tweaks the definition so as to use it to proscribe undefined behavior, so "benign" data race is oxymoronic in those languages. However, the use of memory_order_relaxed is intended to indicate a permitted data race in the first sense but not the second sense.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by schoen on Thursday October 03, 2019 @02:42PM (#21150497)
Thanks for the tremendous detail on this point.

Could you or someone else please give a minimal example of an undefined access in C, just so that I can be sure of whether we're talking about the same phenomena here?

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by jcranmer on Thursday October 03, 2019 @03:15PM (#21150903)
A minimal program (using C11 threads):

   #include <threads.h>
   int x;

   int do_thread(void *) {
     for (int i = 0; i < 10000; i++)
       x = i;
     return 0;
   }
   int main() {
     thrd_t t;
     thrd_create(&t, do_thread, NULL);
     do_thread(NULL);
     thrd_join(&t, NULL);
     return 0;
   }
There is an undefined data race on x, since it is simultaneously accessed from two threads without any synchronization. Replace the declaration of x with `_Atomic int x;`, and the resulting code is well-defined.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by dekhn on Friday October 04, 2019 @08:59AM (#21157159)
thanks, this comment (point 3 in particular) did a great service in clearing up the disconnect.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by dekhn on Friday October 04, 2019 @08:58AM (#21157154)
no programming languages, just the hardware. I think the only way to reasonably think about data races is at the hardware instruction/memory level, not the programming language.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by gpderetta on Thursday October 03, 2019 @12:17PM (#21148687)
they very much are.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by shaklee3 on Thursday October 03, 2019 @02:00PM (#21149893)
Can you point to a source on that? If you have two pthreads in C accessing the same variable, they will definitely not necessarily see the same load/store order, but it's perfectly valid as a form of lazy evaluation to assume the value eventually can be seen.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by gpderetta on Thursday October 03, 2019 @02:29PM (#21150299)
Can't check chapter and verse on the standard right now. Will you take cppreference[1] as authoritative? See the section on data races. The C11 memory model only differ minimally form C++11.

[1] https://en.cppreference.com/w/cpp/language/memory_model

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by shaklee3 on Thursday October 03, 2019 @06:40PM (#21153015)
I'm aware of c++ memory models, but this is exactly what I was talking about. The actual behavior is defined by the hardware, in the programming language is an abstraction on top of that. For certain sizes, you will not get a load or a store that is only partially there. So on x64, you can safely share data between threads knowing that the observed order of that data is completely undefined. But in cases of looking into a view of statistics, that may be perfectly acceptable given the trade-offs.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by jcranmer on Thursday October 03, 2019 @08:35PM (#21153785)
> The actual behavior is defined by the hardware, in the programming language is an abstraction on top of that.

This is a very dangerous way to understand semantics of programming languages. Programming languages are usually defined via some sort of operational semantics on an abstract machine which occasionally bears some resemblance to how processor semantics are defined. But sometimes there is a massive disconnect between processor semantics and language semantics--and perhaps nowhere is that disconnect greater than memory.

In hardware, there is a firm distinction between memory and registers. Any language which approximates hardware semantics (which includes any mid-level or low-level compiler IR) is going to mirror this distinction with the notion of a potentially infinite register set (if pre-register allocation) and use of explicit instructions to move values to and from memory. But in every high-level language, there is no concept of a memory/register distinction: just values floating around in a giant bag of them, often no notion of loads or stores. You can approximate this by annotating values (as C does, with the volatile specifier), but the resulting semantics end up being muddy because you're relying on an imperfect mapping to get to the intended semantics (don't delete this load/store). Optimization that screws up the mapping of the language memory model to the hardware memory model is anticipated, even 30 years ago--that's why C has a volatile keyword.

It is possible, if you are very careful, to write C code that exposes the underlying hardware model that allows you to reason about your program using that model. But this is not typical C code, and instead requires modifying your code in such a way that you make the intended loads and stores explicit. And if you write your code in the typical way and expect it to map cleanly to hardware semantics, you're going to have a bad time.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by shaklee3 on Thursday October 03, 2019 @11:22PM (#21154511)
Coming from a world where latency and performance is paramount, I think it's perfectly acceptable to write code targeted at a specific architecture you know won't change. I understand your points though, and it's definitely not a style you should use in 99% of programming.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by IggleSniggle on Thursday October 03, 2019 @11:27AM (#21148103)
I would call this sampling that could turn into a race condition if it stops being treated as sampling.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by petschge on Thursday October 03, 2019 @10:46AM (#21147599)
Random 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.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by Confusion on Thursday October 03, 2019 @11:11AM (#21147937)
Examples in the literature? This is not a bloody academic exercise?!

I use the term 'race condition' about once a week to point out something may happen before or after something else, because the things are happening in parallel.

Simple example:

me: I just uploaded the file to our shared dropbox

you, refreshing: I don't see it yet

me: race condition

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by dekhn on Thursday October 03, 2019 @11:17AM (#21148008)
eventual consistency is not a race condition.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by Confusion on Friday October 04, 2019 @04:10AM (#21155751)
Of course it is, that's exactly the point. 'Eventual consistency' is the name for situations where a race condition is acceptable and even a feature. It doesn't matter whether it are threads, processes or entirely different computers that are racing. Whether the data is shared via CPU cache, memory, disk or a network. We don't call it "failed eventual consistency" when a data race occurs.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by IggleSniggle on Thursday October 03, 2019 @11:31AM (#21148145)
I would never call this a race condition, but mostly because it does not cause an unrecoverable / system crashing failure state (you and your coworker have a protocol to resolve the inconsistent state).
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by hunter2_ on Thursday October 03, 2019 @09:51AM (#21146909)
The phrase "race condition" is usually not used to describe the harmless asynchronous code you're referring to.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by chrisseaton on Thursday October 03, 2019 @09:56AM (#21146972)
No 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.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by tsbinz on Thursday October 03, 2019 @10:04AM (#21147057)
The tool specifically looks for data races.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by ggggtez on Thursday October 03, 2019 @09:46AM (#21146854)
I think by definition, you are wrong. If the race condition was harmless then it wouldn't be a race condition.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by chrisseaton on Thursday October 03, 2019 @09:59AM (#21146990)
By 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'.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by mffnbs on Thursday October 03, 2019 @10:17AM (#21147216)
You 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.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by chrisseaton on Thursday October 03, 2019 @10:38AM (#21147506)
I didn't realise something as specific as 'race condition' could have a colloquial definition, but ok.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by pure-awesome on Thursday October 03, 2019 @11:17AM (#21148012)
For 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.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by ggggtez on Thursday October 03, 2019 @11:48PM (#21154616)
I 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.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by chrisseaton on Friday October 04, 2019 @06:00AM (#21156214)
> 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.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by zzzcpan on Thursday October 03, 2019 @10:25AM (#21147317)
Didn'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.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by chrisseaton on Thursday October 03, 2019 @10:31AM (#21147395)
> It's not any behavior that depends on timing sequences,

That's literally how 'race condition' is defined in the industry.

Re:Google Is Uncovering Hundreds of Race Conditions Within t... by zzzcpan on Thursday October 03, 2019 @11:03AM (#21147858)
Not true, it's pretty hard to encounter anyone in the industry using the phrase "race condition" without implying a bug.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by tanr54ok on Thursday October 03, 2019 @10:19AM (#21147240)
what? 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.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by chrisseaton on Thursday October 03, 2019 @10:22AM (#21147284)
Event 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.
Re:Google Is Uncovering Hundreds of Race Conditions Within t... by tanr54ok on Thursday October 03, 2019 @01:19PM (#21149392)
So 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.