Delphi 中的抢占式多线程
有没有办法在 Delphi 中做到这一点以及它与 Delphi 中的其他线程处理方法?
I've read about Preemptive Multithreading here and here.
Is there a way to do this in Delphi and how does this compare (advantages and disadvantages) to other methods of threading in Delphi?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您所指的“其他方法”似乎都在使用操作系统的底层线程功能——这是抢占式的。换句话说,选择你认为最方便的那个,它将是先发制人的。
获得非抢占式(又称协作式)线程需要一些额外的工作,通常是将线程转换为“纤程”。
The "other methods" you're referring to all seem to be using the operating system's underlying threading capability -- which is preemptive. In other words, choose whichever you find most convenient, and it'll be preemptive.
Getting non-preemptive (aka cooperative) threading requires a bit of extra work, typically by converting threads to "fibers".
现代版本的 Windows 都是抢占式多任务操作系统。这意味着线程和进程(其中一个进程的存在需要至少一个执行线程)都是被调度并抢占运行的。
因此,“在 Delphi 中是否有办法做到这一点”有以下答案:
最好的答案是使用TThread或任何本机 Windows 线程 或它们周围的包装器。您将拥有抢占式多线程。
您链接中的所有模型都使用普通的 Windows 线程,我怀疑您的问题意味着您对不同的线程技术感到困惑,这些技术主要是用于通信或运行任务(在其他线程上运行的工作作业)的技术。如果这是在这种情况下,您可能需要更新您的问题或询问其他人以寻求这些模型的解释。
Modern versions of Windows are all preemptive multitasking operating systems. This means that threads and processes (where a process to exist requires at least one thread of execution) are all scheduled and preemptively run.
So "is there a way to do this in Delphi" has the following answers:
The best answer is use TThread or any native Windows thread or wrapper around them. You will have preemptive multithreading.
All the models in your link use normal Windows threads and I suspect your question means you're confused about different threading techniques, which are mostly techniques for communication or running tasks (jobs of work that are run on other threads.) If this is the case, you might want to either update your question or ask another looking for an explanation of these models.
您是否看过用户模式调度是在 Windows 7 中引入的。光纤基本上不起作用。 MSDN 网站上有很多这方面的信息,我似乎记得第 9 频道上的一些视频。
Have you looked at User-Mode Scheduling which was introduced in Windows 7. Fibers basically don't really work. There's lots of information on this on the MSDN site and I seem to recall a few videos on Channel 9.