import threading
semaphore = threading.Semaphore(value)
semaphore.acquire()
semaphore.release()
python
import threading
shared_resource = 0
semaphore = threading.Semaphore(1)
def modify_shared_resource():
global shared_resource
semaphore.acquire()
shared_resource += 1
semaphore.release()
threads = []
for _ in range(10):
t = threading.Thread(target=modify_shared_resource)
threads.append(t)
t.start()
for t in threads:
t.join()
print(shared_resource)