C++ Logo

std-proposals

Advanced search

Re: Signals & Slots

From: Thiago Macieira <thiago_at_[hidden]>
Date: Fri, 23 Jul 2021 09:37:55 -0700
On Thursday, 22 July 2021 23:25:14 PDT Tony V E via Std-Proposals wrote:
> Boost Signals2 is about as thread safe as possible (and I helped with the
> design of it)‎, but a slot can still deadlock in a weird edge case.
>
> As long as you don't grab locks in your slots you are fine, but that is
> easier said than done - people call functions that call functions that...
> grab locks that you aren't aware of.

We have the same problem in Qt. As a rule of thumb, never call back to user
code with acquired locks and signal emission counts as calling back to user
code.

Moreover, we often have also to deal with the current object (this) having
been deleted in that very callback. So the rule of thumb is to emit signals at
the very end of your function, after you've dropped the locks and are ready to
return any way.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DPG Cloud Engineering

Received on 2021-07-23 11:37:58