PERL 并行多线程
我正在编写一个涉及多线程的 PERL 脚本。它有一个 GUI,并且要使用的线程数将作为用户输入。根据这个数字,脚本应该生成所有访问同一个子进程的线程。我希望 n 个线程并行工作。但是当我创建循环时,并行处理就会丢失。关于如何克服这个问题有什么想法吗?
I am writing a PERL script involving multithreading. It has a GUI and the number of threads to be used will be taken as user input. Depending on this number, the script should generate threads which all access the same sub. I want the n threads to work in parallel. But when I create a loop, the parallel processing is lost. Any idea as to how to overcome this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信最简单的回答方法是建议您查看类似 POE 的内容。框架食谱网页提供了许多示例,这些示例肯定会成为您原始问题的良好起点。
根据您的 GUI 平台,您可能还需要花时间在框架本身提供的事件循环上。
I believe that the simplest way to answer would be to recommend you to look at something like POE. The framework cookbook webpage provides many examples that surely will be a good starting point for your original issue.
Depending on your GUI platform, you may also want to spend time on event loops provided by the framework itself.
您可能需要在处理循环中偶尔调用threads->yield()函数。 Yield() 函数给出了一个“提示”,让出一个线程的 CPU。
You probably need to call threads->yield() function occasionally in the processing loops. The yield() function gives a "hint" to give up the CPU for a thread.