Diferente pentru blog/counter intre reviziile #3 si #12

Diferente intre titluri:

broken multi threaded counter
Broken counter

Diferente intre continut:

What's the minimum value this code can print:
What's the minimum value this Python code can print:
== code(c) |
== code(python) |
import threading
num_threads = 5
threads = []
for i in xrange(0, num_threads):
  threads.append(threading.Thread(target=increment, args=(count,)))
  threads.append(threading.Thread(
                   target=increment,
                   args=(count,)))
for t in threads:
   t.start()
print counter
==
Basically you're given 5 5 threads that each increment an integer counter variable exactly 10 times. The variable isn't guarded by any lock. You can assume that reading and writing to the variable are atomic operations. What's the minimum value the counter can have after all threads finished.
The fact that the code is in Python doesn't really matter. Basically you're given 5 threads that each increment an integer variable _counter_ exactly 10 times. The variable isn't guarded by any lock. You can assume that reads and writes to the variable are atomic operations. What's the minimum value the counter can have after all threads finished.

Diferente intre securitate:

private
protected

Diferente intre topic forum:

 
8263