简体   繁体   English

C ++:PThread计划与Windows线程

[英]c++: PThread Scheduling vs. Windows Thread

I have some experience with windows threads and am looking into pthreads. 我对Windows线程有一些经验,正在研究pthreads。 I've a question about the pthread scheduling. 我对pthread调度有疑问。 On windows you can set the Process-Priority and within a Process you can set the process-Priority. 在Windows上,您可以设置Process-Priority,而在Process中,可以设置Process-Priority。 The Windows Scheduler executes always the process with the highest Process-Priority, and in the Process the Threads on a Round-Robin. Windows Scheduler始终执行具有最高进程优先级的进程,并且在进程中以循环方式执行线程。

Now to the pthreads you can set the scheduler-policy via sched_setscheduler, and set priority for real-time-modi. 现在到pthread中,您可以通过sched_setscheduler设置调度程序策略,并设置实时修改的优先级。 Everything, wright so far? 一切,莱特到目前为止?

QUESTIONS: 问题:

1) How are pthreads scheduled over different processes? 1)如何在不同的进程上调度pthread?

2) Are real-time-threads performed before threads with lower priority or is there a round-robin? 2)实时线程是否在优先级较低的线程之前执行,或者是否有循环机制?

3) How can i get as much realtime-behavior (fe for i/o -signals) as possible and how much can i get? 3)我如何才能获得尽可能多的实时行为(输入/输出信号的费率),我可以得到多少?

It is important to realise that POSIX threads (pthreads) are specified in a standard that imposes certain minimum requirements on implementations, but also allows them considerable leeway. 重要的是要意识到,POSIX线程(pthreads)是在一个标准中指定的,该标准对实现施加了某些最低要求,但同时也给了它们很大的回旋余地。

pthreads has a concept of Thread Scheduling Contention Scope . pthreads具有线程调度争用范围的概念。 pthreads implementations must support at least one of PTHREAD_SCOPE_SYSTEM and PTHREAD_SCOPE_PROCESS scheduling contention scopes. pthreads实现必须至少支持PTHREAD_SCOPE_SYSTEMPTHREAD_SCOPE_PROCESS调度争用范围之一。

If a thread is scheduled under the PTHREAD_SCOPE_SYSTEM contention scope, it competes equally to be scheduled with all other processes and threads using PTHREAD_SCOPE_SYSTEM on the system. 如果在PTHREAD_SCOPE_SYSTEM争用范围内调度了线程,则在系统上使用PTHREAD_SCOPE_SYSTEM与其他所有进程和线程进行竞争,以平等地竞争该线程。

If a thread is scheduled under the PTHREAD_SCOPE_PROCESS contention scope, it only directly competes with other threads also using PTHREAD_SCOPE_PROCESS in the same process. 如果一个线程是在PTHREAD_SCOPE_PROCESS争用范围内调度的,则它仅在同一进程中也使用PTHREAD_SCOPE_PROCESS与其他线程直接竞争。 How that group of threads is then scheduled with respect to other processes / threads is unspecified by POSIX, but typically each group of threads using PTHREAD_SCOPE_PROCESS in the same process is treated as a single PTHREAD_SCOPE_SYSTEM entity. POSIX未指定如何相对于其他进程/线程调度该组线程,但是通常在同一进程中使用PTHREAD_SCOPE_PROCESS每组线程都被视为单个PTHREAD_SCOPE_SYSTEM实体。

It is common for implementations to only support one of these - for example, Linux supports only the PTHREAD_SCOPE_SYSTEM scheduling contention scope. 实现仅支持其中之一是很常见的-例如,Linux仅支持PTHREAD_SCOPE_SYSTEM调度争用范围。

Under pthreads, runnable higher priority threads always execute in preference to lower priority threads. 在pthreads下,可运行的优先级较高的线程始终优先于优先级较低的线程执行。 With threads at the same priority level, if a thread is using the SCHED_FIFO scheduling policy then it will continue to run until it blocks or yields; 对于具有相同优先级的线程,如果一个线程正在使用SCHED_FIFO调度策略,则它将继续运行直到阻塞或让步;否则,它将继续运行。 if it is using the SCHED_RR scheduling policy then it will also be pre-empted after using up its time quantum. 如果它正在使用SCHED_RR调度策略,则在用完其时间量后也会被抢占。

I do not believe POSIX imposes any constraints on realtime performance - after all, realtime latency is strongly influenced by the underlying hardware. 我认为POSIX不会对实时性能施加任何限制-毕竟,实时延迟受底层硬件的强烈影响。 Apart from setting a realtime scheduling policy ( SCHED_FIFO or SCHED_RR ), you can also get more deterministic latency by locking your process memory using mlockall(MCL_CURRENT | MCL_FUTURE); 除了设置实时调度策略( SCHED_FIFOSCHED_RR )之外,还可以通过使用mlockall(MCL_CURRENT | MCL_FUTURE);锁定进程内存来获得更多确定性延迟mlockall(MCL_CURRENT | MCL_FUTURE); and pre-faulting in the memory you require. 并在您需要的内存中进行预故障处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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