std::function 赋值运算符和调用运算符的并发

std::function concurrency with assignment operator and call operator

std::function::operator=std::function::operator()可以同时调用吗?

线程一上执行std::function::operator=而在线程二[=23=上执行std::function::operator()是否是未定义的行为].

我假设这可能是一个原子操作,我们不能在调用函数之间进行中间操作。我不关心哪一个运行只是因为我们没有处于某种无效状态。

"[res.on.objects]/1 The behavior of a program is undefined if calls to standard library functions from different threads may introduce a data race. The conditions under which this may occur are specified in 20.5.5.9. [ Note: Modifying an object of a standard library type that is shared between threads risks undefined behavior unless objects of that type are explicitly specified as being sharable without data races or the user supplies a locking mechanism. —end note ]" –

评论者:Igor Tandetnik

话虽这么说,但我找到了一种解决方法来做我想做的事。可以在呼叫操作员中进行分配。这意味着我不需要在不同的线程上进行分配。