在多线程程序中最大化并行性的最佳方法是什么? [英] What is the best way to maximize parallelity in multi Threaded program?

查看:83
本文介绍了在多线程程序中最大化并行性的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你有10个线程,在一个函数中你想要最大化它们之间的并行性,最好的方法是什么:



1. with 10个互斥锁,将每个互斥锁分配给一个线程?

2.使用信号量(0,10)?

3.使用数组/互斥体列表?



你会做什么?



谢谢,

Lets say you have 10 threads, in one function and you want to maximize parallelity between them, what is the best way to do that:

1. with 10 mutexes, assign each mutex to a thread?
2. with semaphore (0, 10) ?
3. with array/list of mutexes?

What would you do?

Thanks,

推荐答案

无论如何,如果您希望获得最佳并行化,那么您正在寻找避免工作线程之间同步的方法。



祝你好运

Espen Harlinn
None of them, if you are lookig for optimal parallelization you are looking for ways to avoid sychronization between the worker threads.

Best regards
Espen Harlinn


其中没有一个。所有变体看起来都像是完全乱码。问题本身并没有确切意义。实际上,这取决于那些线程应该做什么,因此对这个问题的进一步讨论根本就没有意义。



我明白这可能是一个学校测试问题。如果是这样,请离开这所学校。基于多项选择题的学校教育,特别是愚蠢的问题,无法教授任何东西。



-SA
None of them. All variants look like complete gibberish. And the question itself does not have exact sense. In reality, it depends on what those threads should do, so further discussion of this question simply makes no sense.

I understand that it could be a school test question. If so, leave this school. A schooling based on multiple-choice questions, especially idiotic ones, cannot teach anything.

—SA


这篇关于在多线程程序中最大化并行性的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆