Using simulation time instead of number of stories

How can I correctly (I mean in multi-threaded G4-based application) exit with saving all data (e.g. G4AnalysisManager and so on) after a certain computational (wall) time?
More similar, how can I mimicre ctme card from mcnp?