Skip to content
Advertisement

why there is no race condition using global python variable

I have the following code:

JavaScript

What I don’t understand is why I do not have a race condition here? We have global variable, two threads, it suppose to give different values when subtracting and adding, but for me it’s always giving 0. How to make race condition in this example? Is the global variable protected with some synchronisation primitive?

Advertisement

Answer

your code can create race condition. but the value that you are printing is zero because of this line.

JavaScript

you declare a value in main which you try to print and it won’t access the global one. try this:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement