lkml.org 
[lkml]   [2001]   [Feb]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
Hi,
the system call sched_yield() doesn't seem to work on Linux 2.2. Does
anyone know of a kernel patch that fixes this ?

Attached below is a small program that uses pthreads and demonstrates that
sched_yield() doesn't work. Basically, the program creates two threads that
alternatively try to yield CPU to each other.


- Mohit

#include <stdio.h>
#include <sched.h>
#include <pthread.h>

static pthread_t thread1, thread2;


static void *thread1_func(void *arg)
{
int i;

for (i=0; i < 5 ;i++) {
printf("Thread1\n");
if (sched_yield()) printf("error in yielding\n");
}
}

static void *thread2_func(void *arg)
{
int i;

for (i=0; i < 5 ;i++) {
printf("Thread2\n");
if (sched_yield()) printf("error in yielding\n");
}
}


int main(int argc, char **argv)
{
pthread_create(&thread1, NULL, thread1_func, NULL);
pthread_create(&thread2, NULL, thread2_func, NULL);

sleep(10);

return 0;
}
\
 
 \ /
  Last update: 2005-03-22 12:52    [W:0.037 / U:2.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site