From b259adff52e903ad593c8cad4c8955a73cc24c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 23 Sep 2025 15:51:33 +0300 Subject: [PATCH] extras/threading_example: add intro --- extras/threading_example/threading_example.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/extras/threading_example/threading_example.py b/extras/threading_example/threading_example.py index 9766682..5b8fa73 100644 --- a/extras/threading_example/threading_example.py +++ b/extras/threading_example/threading_example.py @@ -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