Thread-safe atomic counters
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Feature or enhancement
Python doesn't currently have a thread-safe atomic counter. CPython currently internally uses a few different patterns to implement thread-safe counters. For example, some test code uses appends to a shared list because the implementation of list.append() is atomic.
We should provide a counter that is explicitly thread-safe so that people don't have to rely on other idioms. The minimum initial API should provide:
- atomic increment
- get value (i.e., inspect)
The threading module may be a good place for it.
cc @rhettinger
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the threading module and the existing thread-safe counter patterns described in the issue. Define and test the minimum API for atomic increment and value inspection, including behavior under concurrent access.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100