Hi.
I had a problem setting thread priorities when cross-compiling TX2 using Nsight on the ubuntu host.
Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#define NUM (i < 10000)
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");
pthread_join(tid1, NULL);
pthread_join(tid2, NULL);
printf("EXIT\n");
return 0;
}
When I run this code as root on the host, there is no problem and the priority setting is successful.
When I compile on Nsight and run as root, printf create thread error.
When I manually compile and run on TX2 as root, printf create thread error.
I think there should be no problem with aarch64-linux-gnu compilation on TX2 and x86_64-linux-gnu compilation on the host, and I am running as root, I don’t know why the error occurred