简体   繁体   English

pthread调度

[英]pthread scheduling

I have a project about "simulating a thread scheduler with pthread". 我有一个有关“用pthread模拟线程调度程序”的项目。

I found several problems: 我发现了几个问题:
1. Is the thread lifecycle is the same as linux thread lifecyle? 1.线程生命周期是否与linux线程生命周期相同?
2. In which step of code does scheduling happen (in pthreads), need an example. 2.需要执行代码的哪个步骤(在pthread中)进行调度。
3. Can I implement my own scheduling algorithm or I must use the explicit scheduling of pthreads like (set_sched_param, ...)? 3.我可以实现自己的调度算法,还是必须使用pthread的显式调度,例如(set_sched_pa​​ram,...)?
4. Is there a way to trace process scheduling (graphically) using C? 4.是否有一种方法可以使用C跟踪(图形地)流程调度?

I assume that what you're after is simulating a scheduler for some OS, using pthreads as the basis for your implementation. 我假设您所追求的是使用pthreads作为实现基础来模拟某些OS的调度程序。 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. 您可以做的是为每个模拟线程创建一个pthread,并在操作系统的每个线程原语中对条件变量进行隐式等待。 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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM