一郎 鈴木
unread,Jun 2, 2010, 11:28:39 AM6/2/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to android-ndk
Please show me how to set a priority to a native thread.
I try to set a priority to a native thread which is created in a JNI
method by calling pthread_create.
As the default schedule policy is SCHED_OTHER or SCHED_NORMAL, I can
only set zero priority to the thread.
Although I change the schedule policy to SCHED_FIFO or SCHED_RR and
the priority to "99" by calling pthread_setschedparam,
pthread_setschedparam returns 1(EPERM).
The JNI method is called from a Activity.
I suppose that I can change priority the thread as the process does
not have a a root authority.
Is there any other way to set apriority to a native thread?
Test code is as follows;
I modify hello-jni.c.
--------------------------------------------------------------------
jstring
Java_com_example_hellojni_HelloJni_stringFromJNI(JNIEnv* env, jobject
thiz){
pthread_t tid;
pthread_attr_t tattr;
struct sched_param param;
pthread_attr_int(&tattr);
pthread_attr_getschedparam(&tattr, ¶m);
pthread_attr_setschedparam(&tattr, ¶m);
pthread_create(&tid, &tattr, threadrun, NULL);
param.schedule_priority = 99;
int ret1 = pthread_setschedparam(tid, SCHED_FIFO, ¶m);
param.schedule_priority = 1;
int ret2 = pthread_setschedparam(tid, SCHED_RR, ¶m);
param.schedule_priority = 0;
int ret3 = pthread_setschedparam(tid, SCHED_RR, ¶m);
--------------------------------------------------------------------
[Result]
ret1:1(EPERM)
ret2:1(EPERM)
ret3:0