You may need to manipulate threads, function pointers, functors, lambdas or you can use a dedicated library. Well, everything can be done in C++.
In your comments you are speaking about NodeJS. I guess you want is an asynchronous library for files, networks...
In this case you may take a look at Boost.Asio which ease the use of asynchronous programming in C++.
Here is quick example, partly from their documentation:
class server
{
public:
server(boost::asio::io_service& io_service,
const tcp::endpoint& endpoint)
: acceptor_(io_service, endpoint)
{
do_accept();
}
private:
void do_accept()
{
acceptor_.async_accept(socket_,
[this](boost::system::error_code ec)
{
if (!ec)
{
// Do your stuff here with the client socket when one arrive.
}
do_accept(); // Start another async call for another client.
});
// Your server can do some other stuff here without waiting for a client.
}
tcp::acceptor acceptor_;
};
This is a basic server that accepts some clients asynchronously. The function tcp::acceptor::asyn_accept will return imediatly and call later the callback when a client connect. In our case, this callback is a lambda function; a new feature from C++11.
std::async.asyncin C# enabled asynchronous callbacks for the first time in the language. Async calls can be performed on a single thread as well.