并发编程和并行编程有什么区别? [英] What is the difference between concurrent programming and parallel programming?

查看:279
本文介绍了并发编程和并行编程有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

并发编程和并行编程有什么区别?我问google,但没有找到任何帮助我理解这种差异。你能给我一个例子吗?

What is the difference between concurrent programming and parallel programing? I asked google but didn't find anything that helped me to understand that difference. Could you give me an example for both?

现在我发现这个解释: http://www.linux-mag.com/id/7411 - 但是并发是程序的一个属性vs并行执行是机器的属性

For now I found this explanation: http://www.linux-mag.com/id/7411 - but "concurrency is a property of the program" vs "parallel execution is a property of the machine" isn't enough for me - still I can't say what is what.

推荐答案

如果你使用线程编程),它不一定会被执行(并行执行),因为它取决于机器是否可以处理多个线程。

If you program using threads (concurrent programming), it's not necessarily going to be executed as such (parallel execution), since it depends on whether the machine can handle several threads.

这是一个可视化的例子。非线程机器上的线程:

Here's a visual example. Threads on a non-threaded machine:

        --  --  --
     /              \
>---- --  --  --  -- ---->>

线程机器上的线程:

     ------
    /      \
>-------------->>

破折号表示已执行的代码。正如你所看到的,它们都分开执行,但是线程机器可以一次执行几个单独的部分。

The dashes represent executed code. As you can see, they both split up and execute separately, but the threaded machine can execute several separate pieces at once.

这篇关于并发编程和并行编程有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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