diff --git a/Concurrence_examples/unsafe_thread_example.py b/Concurrence_examples/unsafe_thread_example.py new file mode 100644 index 0000000..132f0ce --- /dev/null +++ b/Concurrence_examples/unsafe_thread_example.py @@ -0,0 +1,20 @@ +import time +import threading + +counter = 0 +threads = [] + +def count(): + global counter + for _ in range(100): + counter += 1 + +for _ in range(100): + thread = threading.Thread(target=count) + thread.start() + threads.append(thread) + +for thread in threads: + thread.join() + +print(f"Count: {counter}") \ No newline at end of file