Browse Source
LinuxScheduler::init() was not really working as it should. This was the result of "ps -Leo class,rtprio,wchan,comm | grep ArduCopter": FF 12 futex_ ArduCopter.elf FF 12 usleep ArduCopter.elf FF 12 hrtime ArduCopter.elf FF 12 poll_s ArduCopter.elf FF 12 hrtime ArduCopter.elf FF 12 hrtime ArduCopter.elf As can be seen all the threads run with the same priority, the one of the main thread. There were basically 2 mistakes: 1) pthread_attr_setschedpolicy() needs to be called before pthread_attr_setschedparam(). Otherwise the latter will just return an error and not set the priority 2) pthread_create() defaults to ignore the priority and inherit the it from the parent thread. pthread_attr_setinheritsched() needs to be called to change the behavior to PTHREAD_EXPLICIT_SCHED. See pthread_attr_setinheritsched(3) for an example program to test the behaviors. Also, it's undefined behavior to call pthread_attr_init() several times on the same pthread_attr_t. Although we could reutilize the same attribute without calling pthread_attr_init() again, lets refactor the code a little bit, so all the pthread calls are in a single place. Then also call pthread_attr_destroy() when we are done.mission-4.1.18
Lucas De Marchi
10 years ago
committed by
Andrew Tridgell
2 changed files with 35 additions and 39 deletions
Loading…
Reference in new issue