0

I am creating a user defined thread library. I use Round-Robin scheduling algorithm and use the context switching method. But, I am unable to know what to do when a thread finishes its execution before the allotted time slot. The program is getting terminated. I actually want to reschedule all the threads, by calling the schedule function when the current thread gets terminated.

I found two ways to overcome this problem.

  1. By calling explicitly thread_exit function at the end of the function that is being executed by the current thread.
  2. By changing the stack contents such that the thread_exit function gets executed after the current function gets terminated.

But I am unable to find how to apply these solutions.... Anybody out there... plz help me...

nitish712
  • 19,504
  • 5
  • 26
  • 34

1 Answers1

0

It sounds like you have a bit of a design flaw. If I'm understanding you correctly, you're trying to implement a solution where you have threads that can be allocated to perform some task and after the task is complete, the thread goes idle waiting for the next task.

If that's true, I think I would design something like a daemon process or service that manages a queue for tasks coming in, a pool of threads responsible for executing the tasks with a controller that listens for new tasks.

Brenda Bell
  • 1,139
  • 8
  • 10