MIXAM
MIXAM

Reputation: 41

Context Switching and Timer Interrupts in xv6

I am trying to modify the scheduling policy in xv6 in which Parent runs first after forking.

childPid = fork();
    if (childPid < 0)
    {
        printf("fork() is failed\n");
    }
    else if (childPid == 0) // child
    {
        printf(" child! ");
        exit();
    }

    printf(" parent! ");

As the scheduler of xv6 always run Parent first i need to context switch to child first so that child will run first and after that parent will run. I have tried using wait() in the code but the wait will fail and i do not want to use fail. I need to modify the context switch when fork is performed by my user level program.

In the xv6 fork() system call i have made the following changes

  acquire(&ptable.lock);
  np->state = RUNNABLE;
  swtch(&cpu->scheduler, proc->context);
  release(&ptable.lock);

but this does not seems to work. Does it have something to do with timer interrupts. How can i achieve to run child first in fork after doing context switching.

Upvotes: 1

Views: 2668

Answers (1)

brokenfoot
brokenfoot

Reputation: 11609

You can use call sched_yield() in the parent code, this will make parent thread to to relinquish the CPU and the other thread will get to run.

Upvotes: 0

Related Questions