C++ DBus和信号处理器竞争条件
假设以下(伪)代码C++ DBus和信号处理器竞争条件,c++,signals,race-condition,dbus,C++,Signals,Race Condition,Dbus,假设以下(伪)代码 intmain(){ //输入例如glib循环 //发出信号` 自动连接=sdbus::createSystemBusConnection(SomeBusName); 自动对象=sdbus::createObject(*(connection.get()),SomePath); 对象->注册表信号(信号A) .onInterface(SomeInterfaceName) .withParameters(); 对象->完成注册(); //创建另一个信号的侦听器`SignalB`
intmain(){
//输入例如glib循环
//发出信号`
自动连接=sdbus::createSystemBusConnection(SomeBusName);
自动对象=sdbus::createObject(*(connection.get()),SomePath);
对象->注册表信号(信号A)
.onInterface(SomeInterfaceName)
.withParameters();
对象->完成注册();
//创建另一个信号的侦听器`SignalB`
//在接收到触发上述发出`信号A`
auto anotherConnection=sdbus::createSystemBusConnection(SomeOtherBusName);
auto-anotherObject=sdbus::createObject(*(anotherConnection.get()),SomeOtherPath);
另一个对象->
上行信号(信号B)
.onInterface(其他接口名称)
.call([对象](字符x){
对象->发射信号(信号A)
.onInterface(SomeInterfaceName)
.带参数(x);
});
另一个对象->finishRegistration();
//现在,许多信号“信号B”开始到达。。。
返回0;
}
使用中的语法。
这听起来像是所谓的信号处理程序竞争条件的配方吗?
(参见示例)
也就是说,object->emitSignal()
是否会导致例如coredump?
如果是这样的话,我们该如何解决这个问题——通过将事件发布到单独的线程并在那里处理它?您链接到的问题是处理Unix信号,而不是DBus
int main() {
// enter e.g. glib loop
// emit a signal `SignalA`
auto connection= sdbus::createSystemBusConnection(SomeBusName);
auto object= sdbus::createObject(*(connection.get()),SomePath);
object->registerSignal(SignalA)
.onInterface(SomeInterfaceName)
.withParameters<char>();
object->finishRegistration();
// create a listener to another signal `SignalB`
// upon receiving which trigger the above to emit `SignalA`
auto anotherConnection= sdbus::createSystemBusConnection(SomeOtherBusName);
auto anotherObject= sdbus::createObject(*(anotherConnection.get()),SomeOtherPath);
anotherObject->
uponSignal(SignalB)
.onInterface(SomeOtherInterfaceName)
.call([object](char x){
object->emitSignal(SignalA)
.onInterface(SomeInterfaceName)
.withArguments(x);
});
anotherObject->finishRegistration();
// now, many signals `SignalB` start to arrive...
return 0;
}