私はシングルスレッドアプリケーションを持っています。以下のコードを使用すると、sched_setscheduler(): Operation not permitted
となります。Linuxのスレッド優先度とスケジューラを変更する
struct sched_param param;
param.sched_priority = 1;
if (sched_setscheduler(getpid(), SCHED_RR, ¶m))
printf(stderr, "sched_setscheduler(): %s\n", strerror(errno));
しかし、以下のようなpthread apiを使用するとエラーは表示されません。単一のスレッドアプリケーションの2つの違いは何ですか?以下の関数はスケジューラと優先順位を実際に変更していますか、エラー処理が不足していますか?
void assignRRPriority(int tPriority)
{
int policy;
struct sched_param param;
pthread_getschedparam(pthread_self(), &policy, ¶m);
param.sched_priority = tPriority;
if(pthread_setschedparam(pthread_self(), SCHED_RR, ¶m))
printf("error while setting thread priority to %d", tPriority);
}
1.アプリケーションを-lpthreadとリンクしました。 2. ulimit -rは0を示していますので、関数assignRRPriorityを80という値で呼び出すことができます。どうしてそれがエラーにならないのですか? – Jimm
'-lpthread'で十分ではありませんが、' -pthread'が必要です(_both_コンパイルの_and_リンク用)。次に、assignRRPriorityは失敗します。 –