Hi!
I am newbie on QNX
I ahve program which has threads that starts more threads and scheduled On round robin
it seems to be working fine but
the threads are preempting with a time slice for the Roundrobin is
very long i.e at the range of about 4-5 minutes. and i didn’t wait for
that long to findout.
may be somebody else changed the ClockPeriod() so i did a fresh
installation and repeated the same still i am getting the same result.
Please somebody pont me in a direction so that i can debug this and
see the roundrobin working as it suppose to with millisecond
timeslices instead of 4-5 minites
here is my actual code
Regards
Sridhar
#include <stdio.h>
#include <sys/neutrino.h>
#include <pthread.h>
#include <sched.h>
#define NumThreads 16
volatile int var1;
volatile int var2;
void *update_thread (void *);
char *progname = “thread2”;
main ()
{
pthread_t threadID [NumThreads];
pthread_attr_t attrib;
struct sched_param param;
int i;
var1 = var2 = 0;
printf ("%s: starting; creating threads\n", progname);
pthread_attr_init (&attrib);
pthread_attr_setinheritsched (&attrib, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy (&attrib, SCHED_RR);
param.sched_priority = getprio (0);
pthread_attr_setschedparam (&attrib, ¶m);
attrib.flags |= PTHREAD_CANCEL_ASYNCHRONOUS;
for (i = 0; i < NumThreads; i++) {
pthread_create (&threadID [i], &attrib, &update_thread, (void
*) i);
}
sleep (20);
/* and then kill them all */
printf ("%s: stopping; cancelling threads\n", progname);
for (i = 0; i < NumThreads; i++) {
pthread_cancel (threadID [i]);
}
printf ("%s: all done, var1 is %d, var2 is %d\n", progname, var1,
var2);
fflush (stdout);
exit (0);
}
/*
- the actual thread.
- The thread ensures that var1 == var2. If this is not the
- case, the thread sets var1 = var2, and prints a message.
- Var1 and Var2 are incremented.
*/
void do_work()
{
static int var3;
var3++;
if ( !(var3 % 100000) )
printf ("%s: thread %d did some work\n", progname,
pthread_self());
}
void *
update_thread (void *i)
{
while (1) {
if (var1 != var2) {
int lvar1, lvar2;
lvar1 = var1; lvar2 = var2;
var1 = var2;
printf ("%s: thread %d, var1 (%d) is not equal to var2
(%d)!\n",
progname, (int) i, lvar1, lvar2);
}
/* do some work here */
do_work();
var1++;
var2++;
}
return (NULL);
}