Re: [PATCH v3 5/8] Introduce run_on_main_thread

Pedro Alves
2019-05-30T13:57:03Z

On 5/30/19 2:20 PM, Tom Tromey wrote:
> Pedro> Can Python's gdb.post_event be built on top of this?
> Pedro> It would fix that nasty "atomically enough" race in gdbpy_run_events,
> Pedro> I guess.
>
> Yes, and actually I wrote a patch to do this once, but I dropped it from
> this series because it was unrelated.
>
>>> + for (auto &item : local)
>>> + item ();
>
> Pedro> I'd think this should swallow errors when calling
> Pedro> each item, instead of letting an exception escape and
> Pedro> discard all other items, since each item call should be
> Pedro> in principle logically unrelated?
>
> Pedro> Maybe we could unit test this code.
>
> I wasn't sure how.

In a unit test, the main thread code could spawn a thread that calls
run_on_main_thread. The main thread would then nest an event loop
to run the main-thread events.
The posted event would write to a global that would unlock the nested
event loop. Something similar to wait_sync_command_done.

> But for this maybe the callback should be noexcept.

Hmm, maybe. But then if someone forgets to try/catch, we end up
aborting gdb. Pick what you prefer, as long as we decide and document
something.

Thanks,
Pedro Alves