Junior — Senior
110
Thread‑safe iterator implementation
任务条件
Implement a class that conforms to Python's iterator protocol and guarantees safe operation when used simultaneously from multiple threads. The iterator must correctly handle concurrent accesses, preserving the integrity of the internal state during iteration.
import threading
class Iterable:
def __init__(self, data):
self.data = data
self.cursor = 0
# TODO: добавить потокобезопасность
def __iter__(self):
return self
def __next__(self):
# TODO: потокобезопасный доступ к self.cursor и self.data
pass