10-31-2005
1,
0
Join Date: Oct 2005
Last Activity: 31 October 2005, 10:19 PM EST
Posts: 1
Thanks Given: 0
Thanked 0 Times in 0 Posts
Round Robin Scheduling
Hi, first post. Well, here goes:
Ok, so I need to build a round robin scheduling algorithm. I understand HOW the algorithm works and I can write it down/show you on paper if you were to ask me "how does the RR scheduling algorithm work?"
Only problem is that I'm having a hell of a time implementing it on the Solaris workstation (5.10). I just can't seem to get started. It just needs to maintain the active/ready queue, have a timeslice of 5seconds for each thread (so long since it's jut a simulator),etc...
I've been looing in the manpages and I found a good example under "thr_sigsetmask" (that's the code example but it doesn't work)
/* cc thisfile.c -lthread -lpthread */
#define _REENTRANT /* basic first 3-lines for threads */
#include <pthread.h>
#include <thread.h>
thread_t user_threadID;
sigset_t new;
void *handler(), interrupt();
main( int argc, char *argv[] ){
test_argv(argv[1]);
sigemptyset(&new);
sigaddset(&new, SIGINT);
switch(*argv[1]) {
case '0': /* POSIX */
pthread_sigmask(SIG_BLOCK, &new, NULL);
pthread_create(&user_threadID, NULL, handler, argv[1]);
pthread_join(user_threadID, NULL);
break;
case '1': /* Solaris */
thr_sigsetmask(SIG_BLOCK, &new, NULL);
thr_create(NULL, 0, handler, argv[1], 0, &user_threadID);
thr_join(user_threadID, NULL, NULL);
break;
} /* switch */
printf("thread handler, # %d, has exited\n",user_threadID);
sleep(2);
printf("main thread, # %d is done\n", thr_self());
} /* end main */
struct sigaction act;
void *
handler(char argv1[])
{
act.sa_handler = interrupt;
sigaction(SIGINT, &act, NULL);
switch(*argv1){
case '0': /* POSIX */
pthread_sigmask(SIG_UNBLOCK, &new, NULL);
break;
case '1': /* Solaris */
thr_sigsetmask(SIG_UNBLOCK, &new, NULL);
break;
}
printf("\n Press CTRL-C to deliver SIGINT signal to the process\n");
sleep(8); /* give user time to hit CTRL-C */
}
void
interrupt(int sig)
{
printf("thread %d caught signal %d\n", thr_self(), sig);
}
void test_argv(char argv1[]) {
if(argv1 == NULL) {
printf("use 0 as arg1 to use thr_create();\n \
or use 1 as arg1 to use pthread_create()\n");
exit(NULL);
}
}
I'm just stumped, how do I start this??? Thanks
--ramoneguru