NVIDIA Jetson TX2设置多线程优先级失败

qq_38543601 2019-05-08 04:58:08

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>

#define NUM (i < 100)

void *fun(void *arg)
{
int policy;
struct sched_param param;
pthread_getschedparam(pthread_self(),&policy,¶m);
if(policy == SCHED_OTHER)
printf("SCHED_OTHER\n");
if(policy == SCHED_RR)
printf("SCHED_RR \n");
if(policy==SCHED_FIFO)
printf("SCHED_FIFO\n");

for (int i = 0; NUM; i++)
{
printf("this is thread%d \n", arg);
}

return (void *)1;
}

int main(int argc, char **argv)
{
int p;
p = getuid();
if(p==0)
printf("The current user is root\n");
else
printf("The current user is not root\n");

int policy,inher;
pthread_t tid1, tid2;
pthread_attr_t attr1, attr2;
struct sched_param param;
int newprioH = 99;
int newprioL = 1;

pthread_attr_init(&attr1);
pthread_attr_init(&attr2);

param.sched_priority = newprioH;
pthread_attr_setschedpolicy(&attr2,SCHED_RR);
pthread_attr_setschedparam(&attr2,¶m);
pthread_attr_setinheritsched(&attr2,PTHREAD_EXPLICIT_SCHED);

param.sched_priority = newprioL;
pthread_attr_setschedpolicy(&attr1,SCHED_RR);
pthread_attr_setschedparam(&attr1,¶m);
pthread_attr_setinheritsched(&attr1,PTHREAD_EXPLICIT_SCHED);

if (pthread_create(&tid1, &attr1, fun, (void*)1) != 0)
printf("create thread1 error\n");
if (pthread_create(&tid2, &attr2, fun, (void*)2) != 0)
printf("create thread2 error\n");

for (int i = 0; NUM; i++)
printf("this is main \n");

printf("THIS IS END\n");

return 0;
}


先是在上位机用Nsight创建了CUDA工程,想分几个线程,设置线程优先级。在TX2上执行后打印创建线程失败。
复制这段代码,直接在上位机vim test.c,复制,然后 sudo gcc test.c -o test -lpthread,sudo ./test。没有打印线程创建失败,执行成功。
继续复制这段代码,在TX2上 ~/目录下vim test.c,复制,然后 sudo gcc test.c -o test -lpthread,sudo ./test。
打印create thread1 error create thread2 error。创建失败。
TX2与上位机均为ubuntu 16.04,求大神讲解。。


...全文
199 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_38543601 2019-05-09
  • 打赏
  • 举报
回复
突然反应过来可能是两边平台不同导致,两端平台输入gcc -v ,target 分别为Target: x86_64-linux-gnu 和 aarch64-linux-gnu。 但又有个疑问,代码在上位机用Nsight直接编译应该就是交叉编译的啊,为什么在板子上执行还是会出错。。 头痛

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧