qtconcurrent dont close correctly
hi everybody, i want to create a unkillable process so i m using a mq pattern run in different thread like this
Code:
void UnkillApp::checkKeepServer()
{
const char* recm = s_recv(socket);
if(recm == NULL)
{
}
else if(strcasecmp(recm, "kill") == 0)
{
s_send(socket, "kill");
p.setProgram(m_cpath);
p.kill();
}
s_send(socket, "keepalive");
}
void UnkillApp::checkKeepClient()
{
int rc = s_send(socket, "areyoualive?");
const char* recm = s_recv(socket);
if(recm == NULL)
{
}
else if(strcasecmp(recm, "kill") == 0)
{
s_send(socket, "kill");
p.setProgram(m_cpath);
p.kill();
}
}
void UnkillApp::run()
{
while (b_run) {
if(b_server)
checkKeepServer();
else
checkKeepClient();
sleep(1);
}
}
void UnkillApp::runInBackground()
{
QtConcurrent::run(this, &UnkillApp::run);
}
void UnkillApp::closethread()
{
b_run = false;
}
and this is the main function
Code:
int main(int argc, char *argv[])
{
UnkillApp s("keepusA", true);
s.runInBackground();
// MainForm w;
MainWindow w;
w.show();
QObject::connect(&w,
SIGNAL(closed
()),
&s,
SLOT(closethread
()));
return a.exec();
}
but after closing mainwindow in debug mode i can see b_run = false; called but application dont exit and i must kill it why? (and i dont run any other process yet)
Re: qtconcurrent dont close correctly
You are accessing b_run from two different threads without any syncrhonisation.
Not saying this is the reason for the observed behavior but wrong nevertheless.
Cheers,
_