Pagini recente » Diferente pentru blog/square-root-trick intre reviziile 89 si 102 | Coding Contest Byte: The Square Root Trick | Diferente pentru blog/square-root-trick intre reviziile 67 si 102 | Atasamentele paginii Perfect2 | Diferente pentru blog/counter intre reviziile 12 si 3
Diferente pentru
blog/counter intre reviziile
#12 si
#3
Diferente intre titluri:
Broken counter
broken multi threaded counter
Diferente intre continut:
What's the minimum value this Python code can print:
What's the minimum value this code can print:
== code(python) |
== code(c) |
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
==
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.
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.
Diferente intre securitate:
Diferente intre topic forum: