Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
RTLinux
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Threads == RT-Linux implements a POSIX API for a thread's manipulation. A thread is created by calling the <code>pthread_create</code> function. The third parameter of <code>pthread_create</code> is a function which contains the code executed by the thread. It is necessary to set thread priorities in RTLinux. Threads with higher priorities can preempt threads with lower priorities. For example, we can have a thread controlling a stepper motor. In order to move the motor fluently, it is necessary to start this thread in strictly regular intervals. This can be guaranteed by assigning a high priority to this thread. The example threads2.c sets different thread priorities. Setting of thread priority is done by code shown below: <syntaxhighlight lang="C"> int init_module(void) { pthread_attr_t attr; struct sched_param param; pthread_attr_init(&attr); param.sched_priority = 1; pthread_attr_setschedparam(&attr, ¶m); pthread_create(&t1, &attr, &thread_code, "this is thread 1"); rtl_printf("Thread 1 started\n"); /* ... */ } </syntaxhighlight> The output the program is as follows. <pre> Thread 1 started Thread 2 started Thread 3 started Message: this is thread 1 Message: this is thread 2 Message: this is thread 2 Message: this is thread 2 Message: this is thread 1 Message: this is thread 1 Message: this is thread 3 Message: this is thread 3 Message: this is thread 3 </pre> The thread 2 has the highest priority and the thread 3 has the lowest priority. The first message is printed by the middle priority thread 1 because it is started a short time before the thread 2.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)