简体   繁体   English

线程范式?

[英]Threading paradigm?

Are there any paradigm that give you a different mindset or have a different take to writing multi thread applications? 是否有任何范例给您不同的心态或对编写多线程应用程序有不同的看法? Perhaps something that feels vastly different like procedural programming to function programming. 也许感觉上有很大的不同,例如从过程编程到函数编程。

Concurrency has many different models for different problems. 并发具有许多用于解决不同问题的模型。 The Wikipedia page for concurrency lists a few models and there's also a page for concurrency patterns which has some good starting point for different kinds of ways to approach concurrency. Wikipedia的并发页面列出了一些模型,并且还有一个页面,用于并发模式 ,这为使用各种并发方法提供了很好的起点。

The approach you take is very dependent on the problem at hand. 您采用的方法非常取决于当前的问题。 Different models solve various different issues that can arise in concurrent applications, and some build on others. 不同的模型解决了并发应用程序中可能出现的各种不同问题,有些模型建立在其他模型的基础上。

In class I was taught that concurrency uses mutual exclusion and synchronization together to solve concurrency issues. 在课堂上我被教导并发一起使用互斥同步来解决并发问题。 Some solutions only require one, but with both you should be able to solve any concurrency issue. 有些解决方案仅需要一个,但同时使用这两个解决方案,您应该能够解决任何并发问题。

For a vastly different concept you could look at immutability and concurrency. 对于截然不同的概念,您可以查看不变性和并发性。 If all data is immutable then the conventional approaches to concurrency aren't even required. 如果所有数据都是不可变的,那么甚至不需要常规的并发方法。 This article explores that topic. 本文探讨了该主题。

I don't really understand the question, but if you start doing some coding using CUDA give you some different way of thinking about multi-threading applications. 我不太了解这个问题,但是如果您开始使用CUDA进行一些编码,则会为您提供有关多线程应用程序的不同思考方式。

It differs from general multi-threading technics, like Semaphores, Monitors, etc. because you have thousands of threads concurrently. 它与一般的多线程技术(例如信号量,监视器等)不同,因为您同时具有数千个线程。 So the problem of parallelism in CUDA resides more in partitioning your data and mixing the chunks of data later. 因此,CUDA中的并行性问题更多地在于对数据进行分区和稍后混合数据块。

Just a small example of a complete rethinking of a common serial problem is the SCAN algorithm. 完全重新思考一个常见串行问题的一个小例子就是SCAN算法。 It is as simple as: 它很简单:

  • Given a SET {a,b,c,d,e} 给定SET {a,b,c,d,e}

I want the following set: 我需要以下设置:

{a, a+b, a+b+c, a+b+c+d, a+b+c+d+e} {a,a + b,a + b + c,a + b + c + d,a + b + c + d + e}

Where the symbol '+' in this case is any Commutattive operator (not only plus, you can do multiplication also). 在这种情况下,符号“ +”是任何交换运算符(不仅是加号,还可以进行乘法运算)。

How to do this in parallel? 如何并行执行此操作? It's a complete rethink of the problem, it is described in this paper . 本文对此进行了全面的重新思考。

Many more implementations of different algorithms in CUDA can be found in the NVIDIA website 可以在NVIDIA 网站上找到CUDA中不同算法的更多实现。

Well, a very conservative paradigm shift is from thread-centric concurrency (share everything) towards process-centric concurrency (address-space separation). 好吧,一个非常保守的范式转换是从以线程为中心的并发(共享所有内容)到以进程为中心的并发(地址空间分离)。 This way one can avoid unintended data sharing and it's easier to enforce a communication policy between different sub-systems. 这样一来,可以避免意外的数据共享,并且可以更轻松地在不同子系统之间实施通信策略。

This idea is old and was propagated (among others) by the Micro-Kernel OS community to build more reliable operating systems. 这个想法是古老的,并由Micro-Kernel OS社区传播(其中包括)以构建更可靠的操作系统。 Interestingly, the Singularity OS prototype by Microsoft Research shows that traditional address spaces are not even required when working with this model. 有趣的是,Microsoft Research的Singularity OS原型表明,使用此模型时,甚至不需要传统的地址空间。

我最喜欢的一个相对较新的想法是事务性存储 :通过确保更新始终是原子性来避免并发问题。

看看OpenMP的有趣变化。

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

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