online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <atomic> #include <thread> #include <iostream> #include <future> #include <syncstream> std::atomic<int> g_cnt = 0; void log(const char* str) { std::osyncstream ss(std::cout); ss << str << std::endl; } void worker1(std::future<int> fut) { log("this is thread 1"); g_cnt++; fut.get(); log("thread 1 exists"); } void worker2(std::promise<int> prom) { log("this is thread 2"); g_cnt++; prom.set_value(10); log("thread 2 exists"); } int main() { std::promise<int> prom; std::future<int> fut = prom.get_future(); // Fire the 2 threads: std::thread t1(worker1, std::move(fut)); std::thread t2(worker2, std::move(prom)); t1.join(); t2.join(); log("main exists"); }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue