Atomic function pointers
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
Following the discussion in https://github.com/rust-lang/rust/issues/51559 I am opening this to track the lack of atomic function pointers in the std library (and the ecosystem in general).
We currently have std::sync::atomic::AtomicPtr but it does not work with function pointers by design:
fn foo() {}
static Foo: AtomicPtr<fn()->()> = AtomicPtr::new(foo);
emits
error[E0308]: mismatched types
--> src/main.rs:5:50
|
5 | static Foo: AtomicPtr<fn()->()> = AtomicPtr::new(foo);
| ^^^ expected *-ptr, found fn item
|
= note: expected type `*mut fn()`
found type `fn() {foo}`
This is at the pure brainstorming stage, but enabling this use case is probably going to need an AtomicFnPtr or similar type unless we retrofit AtomicPtr to also work with fn items.
EDIT: relevant threads/rfcs:
[0] pre-RFC: Extended atomic types proposes a generic atomic type that uses constraints to be generic. I don't know if that approach can be feasible extended to function pointer types.
[1] RFC 1543 (merged): Add more integer atomic types. Only mentions AtomicPtr, but it does not mention pointers to functions.
[2] Function pointers can be stored in atomic usizes just fine.
Contributor guide
No contributing guide indexed for this repository
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 with the issue's discussion and the linked issues 51559 and the referenced atomic-type threads and RFC 1543. Examine the existing std::sync::atomic::AtomicPtr behavior and compare the proposed AtomicFnPtr approach with retrofitting AtomicPtr. Done would require a settled design and an accepted RFC; no implementation file or test is named.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100