質問

I have a project about "simulating a thread scheduler with pthread".

I found several problems:
1. Is the thread lifecycle is the same as linux thread lifecyle?
2. In which step of code does scheduling happen (in pthreads), need an example.
3. Can I implement my own scheduling algorithm or I must use the explicit scheduling of pthreads like (set_sched_param, ...)?
4. Is there a way to trace process scheduling (graphically) using C?

役に立ちましたか?

解決

I assume that what you're after is simulating a scheduler for some OS, using pthreads as the basis for your implementation. What you can do is to create a pthread for each simulated thread, and put an implicit wait on a condition variable in each of the threading primitives of your OS. You can then, by picking which condition variable to signal, decide which thread gets to run when. I'm glossing over the details (ask if you want more info), but it's fairly straight-forward to implement.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top