Do really need a count lock on Multi threads with one CPU core?

Posted by MrROY on Stack Overflow See other posts from Stack Overflow or by MrROY
Published on 2012-09-22T03:28:28Z Indexed on 2012/09/22 3:37 UTC
Read the original article Hit count: 191

If i have some code looks like this(Please ignore the syntax, i want to understand it without a specified language):

count = 0

def countDown():
  count += 1

if __name__ == '__main__':
    thread1(countDown)
    thread2(countDown)
    thread3(countDown)

Here i have a CPU with only one core, do i really need a lock to the variable count in case of it could be over-written by other threads.

I don't know, but if the language cares a lot, please explain it under Java?C and Python, So many thanks.

© Stack Overflow or respective owner

Related posts about multithreading

Related posts about operating-system