Yocto Mickledore: Group RT Scheduling Issues with pthread\_create
In this article, we will discuss the issue of premature application exit when using the pthread\_create function in the Yocto Project 6.1 Mickledore release. We will cover the key concepts related to this problem and provide a detailed context to help you understand and resolve the issue.
Introduction
The Yocto Project is an open-source collaboration project that provides templates, tools, and methods to help create custom Linux-based systems for embedded devices. The Mickledore release (6.1) introduced several new features and improvements, but it also introduced a problem when using the pthread\_create function in group RT scheduling.
Group RT Scheduling
Group RT scheduling is a feature in the Linux kernel that allows for the creation of scheduling groups with a common priority. This feature is useful for applications that require real-time behavior, as it ensures that all threads in the group are scheduled with the same priority, preventing priority inversion and other scheduling-related issues.
pthread\_create Function
The pthread\_create function is used to create a new thread in a process. In the Yocto Project, this function can be used to create threads with real-time behavior by specifying the appropriate scheduling parameters. However, in the Mickledore release, using this function in group RT scheduling can result in premature application exit.
Issue Details
The issue occurs when using the pthread\_create function in group RT scheduling. The application will exit prematurely, without any error message or indication of the cause of the problem. This issue has been reported by several users and has been traced to a problem with the way the Linux kernel handles group RT scheduling and the pthread\_create function.
Resolution
The issue has been fixed in later releases of the Yocto Project. If you are experiencing this problem, it is recommended that you upgrade to a later release. If upgrading is not an option, there are several workarounds that you can use to resolve the issue.
One workaround is to use the CLONE\_THREAD flag when calling the clone system call instead of the pthread\_create function. This will create a new thread with the same scheduling parameters as the calling thread, effectively achieving the same result as using the pthread\_create function.
Another workaround is to use the pthread\_attr\_setschedpolicy function to set the scheduling policy for the new thread instead of specifying the scheduling parameters in the pthread\_create function. This will allow you to create a new thread with real-time behavior without encountering the premature application exit issue.
The premature application exit issue when using the pthread\_create function in group RT scheduling in the Yocto Project 6.1 Mickledore release can be a frustrating problem. However, by understanding the key concepts related to this issue and using the workarounds provided, you can resolve the issue and continue to use the Yocto Project to create custom Linux-based systems for embedded devices.
References
#include
int main() {
struct sched\_param param;
pthread\_attr\_t attr;
pthread\_attr\_init(&attr);
pthread\_attr\_setschedpolicy(&attr, SCHED\_RR);
param.sched\_priority = 99;
pthread\_attr\_setschedparam(&attr, ¶m);
pthread\_t thread;
pthread\_create(&thread, &attr, NULL, NULL);
pthread\_attr\_destroy(&attr);
// ...
pthread\_join(thread, NULL);
return 0;
}