Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example async memory reporting
// pseudo-pythonish-cpp, whatever
total_reporters = len(reporters)
do_memory_reports:
// this is on the main thread
for r in reporters:
main_thread_dispatch(new DoReportEvent(r));
start_timer(on_report_done);
on_report_done(r):
total_reporters--;
if (total_reporters == 0 || is_timed_out()):
// call the finishReporting callback that was registered
cancel_timer();
finishReporting();
else:
// do nothing, just wait for the next event
do_report(r):
// this is called on main thread, it's a different event (do_memory_reports has completed)
r->report(); // this can dispatch events to other threads etc
example_reporter:
post_task_to_other_thread(runs_on_other_thread);
runs_on_other_thread:
// this is on the non-main-thread
// do some stuff
// signal that this reporter is done
main_thread_dispatch(on_report_done);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.