Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAtomic function pointers #2481
Comments
gnzlbg
referenced this issue
Jun 20, 2018
Open
Storing a function pointer in a const usize works on nightly #51559
This comment has been minimized.
This comment has been minimized.
|
The main issue that I can see here is that we would need variadic generics to make this work for all possible argument lists for the inner function type. Also have you considered whether |
This comment has been minimized.
This comment has been minimized.
|
Variadic generics aren't even enough, since fn types can have higher rank lifetimes (e.g., |
This comment has been minimized.
This comment has been minimized.
Thinking of:
I think "null" is a perfectly valid value for a raw fn pointer, but I don't know if it is possible to have one in Rust: |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Then I think we need |
This comment has been minimized.
This comment has been minimized.
|
At this point you might as well just use my crate. |
This comment has been minimized.
This comment has been minimized.
|
Ping @gnzlbg; what's the state of this? ( You can do: |
gnzlbg commentedJun 20, 2018
•
edited
Following the discussion in rust-lang/rust#51559 I am opening this to track the lack of atomic function pointers in the
stdlibrary (and the ecosystem in general).We currently have
std::sync::atomic::AtomicPtrbut it does not work with function pointers by design:emits
This is at the pure brainstorming stage, but enabling this use case is probably going to need an
AtomicFnPtror similar type unless we retrofitAtomicPtrto also work withfnitems.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.