I experience strange behavior in the software I'm working on. This is a real-time controller written in C ++, running on Linux, and it makes extensive use of multithreading.
When I run the program without asking it in real time, everything works as I expect. But when I ask you to switch to real time, there is a distinctly reproducible error that allows the application to crash. I think it must be some kind of dead end thing, because it is a mutex that picks up a timeout and ultimately raises a statement.
My question is how to find him. Looking at the return line from the produced kernel is not very useful, since the cause of the problem lies somewhere in the past.
The following code switches between "normal" and "realtime" modes:
In main.cpp (simplified return code is checked through statements):
if(startAsRealtime){ struct sched_param sp; memset(&sp, 0, sizeof(sched_param)); sp.sched_priority = 99; sched_setscheduler(getpid(), SCHED_RR, &sp);}
In each thread (a simplified return code is checked through statements):
if(startAsRealtime){ sched_param param; pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); pthread_attr_getschedparam(&attr, ¶m); param.sched_priority = priority; pthread_attr_setschedpolicy(&attr, SCHED_RR); pthread_attr_setschedparam(&attr, ¶m);}
Thanks in advance
source share