Delphi 中的抢占式多线程

发布于 2024-10-03 18:46:08 字数 382 浏览 0 评论 0原文

我在此处此处

有没有办法在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

居里长安 2024-10-10 18:46:08

您所指的“其他方法”似乎都在使用操作系统的底层线程功能——这是抢占式的。换句话说,选择你认为最方便的那个,它将是先发制人的。

获得非抢占式(又称协作式)线程需要一些额外的工作,通常是将线程转换为“纤程”。

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".

通知家属抬走 2024-10-10 18:46:08

现代版本的 Windows 都是抢占式多任务操作系统。这意味着线程和进程(其中一个进程的存在需要至少一个执行线程)都是被调度并抢占运行的。

因此,“在 Delphi 中是否有办法做到这一点”有以下答案:

  • 您的单线程 Delphi 应用程序已经与其他应用程序抢先调度
  • 如果您编写多线程 Delphi 应用程序,它也将被抢先调度。 您必须付出相当大的努力来编写非抢占式模型,例如应用程序中的协作线程模型。一种方法可能是使用 协程这里是一个使用 Delphi 7 的示例

最好的答案是使用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:

  • Your singlethreaded Delphi application is already preemptively scheduled with the other applications
  • If you write a multithreaded Delphi application, it also will be. You would have to go to considerable effort to write a non-preemptive model, such as a cooperative threading model in your application. One approach might be to use coroutines; here is an example using Delphi 7.

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.

热鲨 2024-10-10 18:46:08

您是否看过用户模式调度是在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文