Full name of submitter (unless configured in github; will be published with the issue): Jim X
Consider this example:
#include <thread>
#include <atomic>
int main(){
std::atomic<bool> flag = false;
std::jthread t1([&](){
auto p = operator new(sizeof(int)); // #1
while(!flag.load(std::memory_order::acquire));
operator delete(p); // #2
});
std::jthread t2([&](){
auto p2 = operator new(sizeof(int)); // #3
flag.store(true,std::memory_order::release);
});
}
In this example, both #1 and #3 happen-before #2. Can both #1 and #3 return the same address? The relevant rule is [basic.stc.dynamic.allocation] p2
If the request succeeds, the value returned by a replaceable allocation function is a non-null pointer value ([basic.compound]) p0 different from any previously returned value p1, unless that value p1 was subsequently passed to a replaceable deallocation function.
In a multithread context, it's hard to say what "previously returned" and "was subsequently passed to a replaceable deallocation function" mean. There is no global timeline across different threads.
Suggested Resolution:
We may need to define what "previously returned" and "was subsequently passed to a replaceable deallocation function" in terms of happens-before.
Full name of submitter (unless configured in github; will be published with the issue): Jim X
Consider this example:
In this example, both
#1and#3happen-before#2. Can both#1and#3return the same address? The relevant rule is [basic.stc.dynamic.allocation] p2In a multithread context, it's hard to say what "previously returned" and "was subsequently passed to a replaceable deallocation function" mean. There is no global timeline across different threads.
Suggested Resolution:
We may need to define what "previously returned" and "was subsequently passed to a replaceable deallocation function" in terms of happens-before.