We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
58e587b
risc-v/K230
GCC
创建两个线程,其中一个设置为高优先级,两个线程同时获取mutex时,会导致高优先级线程被重新改为默认优先级。具体复现case见代码。
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <pthread.h> #include <unistd.h> #include <errno.h> #include <time.h> #define rt_mutex_create 22 #define rt_mutex_delete 23 #define rt_mutex_take 24 #define rt_mutex_release 25 pthread_t tid; void* mutex; static void* subthread(void* arg) { int ret; int policy; struct sched_param param; ret = pthread_getschedparam(pthread_self(), &policy, ¶m); printf("%s get prio: %d, %d\n", __func__, ret, param.sched_priority); param.sched_priority = 0; ret = pthread_setschedparam(pthread_self(), policy, ¶m); ret = pthread_getschedparam(pthread_self(), &policy, ¶m); printf("%s get prio: %d, %d\n", __func__, ret, param.sched_priority); syscall(rt_mutex_take, mutex, -1); sleep(1); syscall(rt_mutex_release, mutex); ret = pthread_getschedparam(pthread_self(), &policy, ¶m); printf("%s get prio: %d, %d\n", __func__, ret, param.sched_priority); return 0; } int main(int argc, char** argv) { int ret; int policy; struct sched_param param; if (argc != 2) { printf("0: test main thread\n1: test subthread\n"); return -1; } mutex = (void*)syscall(rt_mutex_create, "driver_test", 0); ret = pthread_getschedparam(pthread_self(), &policy, ¶m); printf("%s get prio: %d, %d\n", __func__, ret, param.sched_priority); param.sched_priority = 0; ret = pthread_setschedparam(pthread_self(), policy, ¶m); ret = pthread_getschedparam(pthread_self(), &policy, ¶m); printf("%s get prio: %d, %d\n", __func__, ret, param.sched_priority); pthread_create(&tid, NULL, subthread, 0); if (atoi(argv[1])) usleep(100000); syscall(rt_mutex_take, mutex, -1); sleep(1); syscall(rt_mutex_release, mutex); ret = pthread_getschedparam(pthread_self(), &policy, ¶m); printf("%s get prio: %d, %d\n", __func__, ret, param.sched_priority); pthread_join(tid, 0); syscall(rt_mutex_delete, mutex); return 0; }
The text was updated successfully, but these errors were encountered:
不是,这个为什么是混用呢,为什么不是如果是rt_mutex的,就在内核中直接使用;如果是pthread_mutex,就按pthread的方式来。
Sorry, something went wrong.
用户程序使用pthread_mutex完全没有问题,上述case只是一个模拟,比如某些设备驱动在kernel中调用了rt_mutex_take,那对应的用户态线程使用了这个设备也相当于使用了rt_mutex。 这个问题不只是在用户态会存在,kernel中的task也会存在同样的问题,如果task在运行过程中调用rt_thread_control来改变优先级,在使用rt_mutex后,也会导致task的优先级被重新调整为init_priority。 @BernardXiong
No branches or pull requests
RT-Thread Version
58e587b
Hardware Type/Architectures
risc-v/K230
Develop Toolchain
GCC
Describe the bug
创建两个线程,其中一个设置为高优先级,两个线程同时获取mutex时,会导致高优先级线程被重新改为默认优先级。具体复现case见代码。
Other additional context
The text was updated successfully, but these errors were encountered: