|
Titlul: Broken counter Scris de: Cosmin Negruseri din August 22, 2012, 23:33:51 http://infoarena.ro/blog/counter
Titlul: Răspuns: Broken counter Scris de: Dumitran Adrian Marius din August 23, 2012, 00:13:01 eu votez 10 in baza 2 sau 10 pastrez suspans :)
Titlul: Răspuns: Broken counter Scris de: Posea Elena din August 23, 2012, 00:25:56 deci... intrebarea e care e numarul maxim de coliziuni care pot aparea? (coliziune= moment in care doua sau mai multe fire incearca sa incrementeze variabila in aproape acelasi timp; daca asta se intampla variabila va fi incrementata numai de un fir, si anume de primul, sau nu va fi incrementata deloc? );
Titlul: Răspuns: Broken counter Scris de: Stefan-Alexandru Filip din August 23, 2012, 01:32:40 The fact that you chose python for this code is very confusing to me.
Titlul: Răspuns: Broken counter Scris de: Cosmin Negruseri din August 23, 2012, 03:07:43 Think of it as a pseudocode example, instead of Python if that makes it less confusing :).
Python threading sucks but the code is somewhat shorter than a Java equivalent. Titlul: Răspuns: Broken counter Scris de: Cosmin Negruseri din August 23, 2012, 03:55:48 @t3st your example has a small bug.
Titlul: Răspuns: Broken counter Scris de: Radu Berinde din August 23, 2012, 05:51:23 2:
Thread 1 reads value 0 Thread 2 does 9 iterations, thread 3-5 all their 10 iterations (the ordering doesn't matter) Thread 1 writes value 1 Thread 2 reads value 1 Thread 1 reads and writes etc until it completes all its iterations Thread 2 writes value 2 Basically what t3st said, he was just missing "thread 1 completes the rest of the iterations" before thread 2 does the final write. Titlul: Răspuns: Broken counter Scris de: Cosmin Negruseri din Septembrie 04, 2012, 22:56:15 As Radu and others have said the answer is 2.
Titlul: Răspuns: Broken counter Scris de: Cosmin Negruseri din Septembrie 07, 2012, 22:36:52 Radu, I've tried with more threads and more increments and you start seeing interesting numbers even if Python uses GIL.
|