Can a linux program be run deterministically under emulation?

49 views Asked by At

Regardless of language and operation system, its simple to create nondeterminstic programs.
For example:

#include <iostream>
#include <thread>

int main()
{
    std::thread t1([](){
        for (int i = 0; i < 10; ++i){
        std::cout << i << std::endl;
    }
    });
    std::thread t2([](){
        for (int i = 0; i < 10; ++i){
        std::cout << i << std::endl;
    }
    });
    t1.join();
    t2.join();
    return 0;
}

Due to the above race condition, this program has the potential to print different values each time the program is run.

Question: Without modifying the binary, is there a way to run this program so that it prints the same results every time? I was thinking there might be some kind of emulator that could run linux programs this way.

0

There are 0 answers