extras/threading_example: add intro
This commit is contained in:
parent
e41e132b60
commit
b259adff52
1 changed files with 20 additions and 1 deletions
|
@ -1,5 +1,24 @@
|
||||||
"""
|
"""
|
||||||
This program adds
|
This program runs a loop that adds +1 to different cells in an array.
|
||||||
|
|
||||||
|
Run it as:
|
||||||
|
python threading_example.py WORKERS ITERATIONS
|
||||||
|
where WORKERS is the number of threads,
|
||||||
|
and ITERATIONS is how much work each thread does.
|
||||||
|
|
||||||
|
In the single threaded case, when N == 1, the 'counters' variable
|
||||||
|
below starts out as
|
||||||
|
[0, 0, 0]
|
||||||
|
then becomes
|
||||||
|
[1, 0, 0]
|
||||||
|
then
|
||||||
|
[1, 1, 0]
|
||||||
|
... and a little bit later
|
||||||
|
[2, 1, 1]
|
||||||
|
and at the end
|
||||||
|
[N, N, N]
|
||||||
|
|
||||||
|
What happens in the multi-threaded case, when N > 1? Try and see!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue