diff --git a/README.md b/README.md index 7bf9aef..4692faf 100644 --- a/README.md +++ b/README.md @@ -2034,7 +2034,7 @@ Threading * **CPython interpreter can only run a single thread at a time.** * **That is why using multiple threads won't result in a faster execution, unless at least one of the threads contains an I/O operation.** ```python -from threading import Thread, RLock +from threading import Thread, RLock, Semaphore, Event, Barrier ``` ### Thread @@ -2063,6 +2063,13 @@ with lock: ... ``` +### Semaphore, Event, Barrier +``` + = Semaphore(value=1) # Lock that can be acquired 'value' times. + = Event() # Method wait() blocks until set() is called. + = Barrier(n_times) # Method wait() blocks until it's called n_times. +``` + ### Thread Pool Executor ```python from concurrent.futures import ThreadPoolExecutor diff --git a/index.html b/index.html index b3f5b29..136268a 100644 --- a/index.html +++ b/index.html @@ -1793,7 +1793,7 @@ db = connector.connect(host=<str>, user=<str>, password=<str>,

#Threading

  • CPython interpreter can only run a single thread at a time.
  • That is why using multiple threads won't result in a faster execution, unless at least one of the threads contains an I/O operation.
  • -
from threading import Thread, RLock
+
from threading import Thread, RLock, Semaphore, Event, Barrier
 
@@ -1819,6 +1819,11 @@ lock.release() ... +

Semaphore, Event, Barrier

<Semaphore> = Semaphore(value=1)     # Lock that can be acquired 'value' times.
+<Event>     = Event()                # Method wait() blocks until set() is called.
+<Barrier>   = Barrier(n_times)       # Method wait() blocks until it's called n_times.
+
+

Thread Pool Executor

from concurrent.futures import ThreadPoolExecutor
 with ThreadPoolExecutor(max_workers=None) as executor:
     <iter>   = executor.map(lambda x: x + 1, range(3))         # (1, 2, 3)