0
why constexpr fails for tydeid
Refer code below: https://www.sololearn.com/en/compiler-playground/cWMZQf1R2563 test function works perfectly fine and no issue about it. Now if I have typeid function which is evaluated at compile time (unlike dynamic_cast). So, if typeid is compile time evaluation, why testnew function fails to compile (To observe this compilation failure, uncomment function call of last two lines in main function)?
1 Odpowiedź
0
Yes, using std::future and std::promise in C++ can be part of multithreaded code, but they don’t create threads on their own.
• If you’re using std::async(...), then a new thread may be created depending on the policy (std::launch::async or deferred).
• If you’re using std::promise and manually setting the value in another thread, then you are responsible for creating the thread using std::thread.
Example:
std::promise<int> p;
std::future<int> f = p.get_future();
std::thread t([&p]() {
p.set_value(42); // this runs in a separate thread
});
int value = f.get(); // blocks in main thread until value is set
t.join();
Here:
• The set_value is run in a separate thread.