The problem with this is that I want to be calculating the reactor in real time and obviously this main loop pauses with the use of 'cin << cmd'. Now from what I know, the solution to this would be multi-threading. One thread running the input commands and the other running the calculate functiuon.
Is multi-threading the solution to this problem?
How would I go about doing this? (preferably without WIN32 API)
And, would this require a dualcore proccesor?
1. Figure out how to poll for input. In this case, the curses API should probably be able to help you.
2. Throw the calculation off to another thread. In this case, it would be a performance gain (albeit the slightest) as well. Unfortunately, it would greatly increase the complication of the program. std::thread should be able to help you here.
"I'm making a simple console based nuclear reactor sim game."
I was thinking of creating the exact same thing a while back. Strange. Any road...
Based on what you've said, the main thread is waiting for input. As you know, this would suspend the entire program until something is given as input. Of course, this is not ideal since computations such as reactor temperatures, water pressure, etcetera need to be continuously updated.
The resolution to this would indeed be threading. I have something like this in mind:
: // Initialise all data-members
// ...and so on...
staticvoid Update( void *Args_ );
void Reactor_Information::Update( void *Args_ )
Reactor_Information *Info_( static_cast< Reactor_Information * >( Args_ ) );
// Update the information...
int main( )
Which ever thread calls "Reactor_Information::Update( )" will attain the lock which in turn will allow the thread to update the reactor's information -- this allows the main thread to wait for input while the reactor information is being periodically updated.
[Note -- The declaration of "Reactor_Information::Update( )" may vary depending on the library you choose -- end note]
Threading libraries come is different forms:
-- The OS's API
-- C++11's Standard Library
"And, would this require a dualcore proccesor?"
No; the processor will use context switching as they all do.