mirror of
https://github.com/autistic-symposium/web3-starter-py.git
synced 2025-05-17 22:20:22 -04:00
26 lines
No EOL
346 B
Python
26 lines
No EOL
346 B
Python
#!/usr/bin/env python3
|
|
|
|
import threading
|
|
|
|
counter = 0
|
|
threads = []
|
|
|
|
lock = threading.Lock()
|
|
|
|
|
|
def count_with_lock():
|
|
|
|
global counter
|
|
|
|
for _ in range(100):
|
|
with lock:
|
|
counter += 1
|
|
|
|
|
|
for _ in range(100):
|
|
thread = threading.Thread(target=count_with_lock)
|
|
thread.start()
|
|
threads.append(thread)
|
|
|
|
|
|
print(counter) |