We have implemented a special communication protocol. In a control manager, we are managing multiple connections by giving some connection ids. Whenever a message is received, a function in c++ is called by the library. That callback function also calls a registered CTRL++ function.
Whenever we receive a lot of messages simultaneously or consecutively and fast enough, mostly the control manager crashes silently, but sometimes it reads "error unwinding stack" etc.
What is the best approach to call functions in of CTRL in control extensions, in order to avoid race conditions. Does the api provide something to help run CtrlFunc's in a synchronous way?
The callback function in the control extension is as follows:
Code: Select all
converters::frame_to_json_converter<json::json_template_complete> fjc(CtrlCmdInterfaceExternHdl::jtc);
auto frame_json = fjc.convert_frame_to_json(frame);
RecVar vars;
auto var = converters::wstring_to_string(frame_json);
vars.append(new TextVar(var.c_str()));
vars.append(new TextVar(host));
vars.append(new UIntegerVar(port));
Controller* p = Controller::thisPtr;
//p->startFunc(callback, &vars);
try
{
CharString con_callback = "returnResponse";
for (auto const& conn : CtrlCmdInterfaceExternHdl::active_connections)
{
if (conn.second.is_equal(host, port))
{
con_callback = conn.second.callback_func;
}
}
CtrlThread *thread = 0;
CtrlFunc *func = Controller::thisPtr->findFunc(con_callback, CtrlCmdInterfaceExternHdl::scr);
CtrlCmdInterfaceExternHdl::scr->startThread(thread, func, &vars);
}