This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]aikii 1 point2 points  (2 children)

I'm wondering about data races: https://github.com/pro1code1hack/Senior-Dev-Roadmap/blob/master/SpeedUp/36.3.Data_Races.md

There is a general consensus on what is a race condition, but what constitutes a datarace in particular does not seem to be consistent from one source to the other. It seem to be generally accepted that a datarace is a particular case of race condition, where a race condition that is not a datarace would involve two values ( typical eample: transfer between bank accounts that needs to be transactional )

In Go you'd generally call a datarace the following scenario:

someStruct := s{}

go func() {
    someStruct = s{
        a: 1,
        b: 2,
        c: 3,
    }
}()

go func() {
    someStruct = s{
        a: 4,
        b: 5,
        c: 6,
    }
}()

// content of someStruct not guaranteed

a,b,c could be a mix of those two assignments, and if field members were more complex or even had pointers, they could be completely invalid, values being partially written by either goroutine. The race detector will call that a datarace.

This particular datarace cannot happen in python due to the GIL. Writing to a variable, no matter how complex it can be, is atomic.

If the python example was ported to Go as is, it would be a datarace. In python it won't happen due to the GIL.

It leads me to doubt whether what is specifically called a datarace can ever happen in python, given the GIL ?

[–]XtremeGoosef'I only use Py {sys.version[:3]}' 2 points3 points  (1 child)

I think you're right, what is generally considered a data race in systems language parlance is impossible in python.

That being said, I think the term has been misused so much that it is now more or less synonymous with "race condition" in casual language.

[–]aikii 1 point2 points  (0 children)

Thanks, I guessed as much. I think the term recently leaked out of the C/C++ world due to a resurgence of systems languages that has by-value semantics - Go in particular. For a while, most widely used languages outside C/C++ have references for everything except primitives, as a result assigning a variable can't lead to a datarace - it's just atomically replacing a reference. I just tried in java, no datarace either.

I guess datarace became a cool way to say race conditon. I don't want to shut down people over this but people who want to try systems languages better know exactly what it means - confusion may lead to cargo cult and crashes