Integrations (PTC products, 3rd party products and code) > Code integration (Ada, ARINC 653, C, C#, C++, IDL, Java, SQL and VB) > C++ code > Generating C++ code > Generating C++ code > Concepts > Single threaded message passing (C++ code)
  
Single threaded message passing (C++ code)
If you want calls to the Class to be asynchronous but do not want to introduce additional threads, you can apply the «C++ Deferred» stereotype to the Class. All the Operations in the Class must not have return values.
When the «C++ Deferred» stereotype is applied to a Class, ACS generates a proxy class for the Class. Each proxy class derives from a class called AtegoDeferredDispatch. This class uses a shared queue to keep track of method calls for all deferred classes in the system. Method calls to the proxy class are asynchronous (so control returns to the caller immediately) and are placed on the shared queue.
To activate the deferred processing your code must call the static method "MainLoop" on the AtegoDeferredDispatch class. The MainLoop method will continuously process events on the shared queue, dispatching them to the real class. MainLoop will exit when the policy (we'll discuss policy below) class' "ShouldExit" function returns true.
The AtegoDeferredDispatch class is templated. It takes a policy class that must implement the Boolean method "ShouldExit" that determines when the AtegoDeferredDispatch class' MainLoop method should exit. PTC provides one example policy class that will cause ShouldExit to return true when the user presses return on the keyboard but you may implement your own alternative policy class.
When generating C++ code using an Animation ACS Code Generator DLL, ACS generates the following code:
A main() function much like it does normally.
An instance of the class you select as the "harness" class.
A MainLoop() call on the AtegoDeferredDispatch class, for example:
int main()
{

INIT_SIMULATION
GameController* pObject = new GameController();
AtegoDeferredDispatch<ExitOnReturnPressed>::MainLoop();
delete pObject;
END_SIMULATION
return 0;
}
If you want to see an example model that uses the «C++ Deferred» stereotype, see the "Active Deferred Ball Game Example" model that is provided in the Examples database.