可以多线程单处理器系统上实现? [英] Can multithreading be implemented on a single processor system?

查看:245
本文介绍了可以多线程单处理器系统上实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我始终遵循该多线程只能在多个处理器系统,其中有一个以上的处理器将被分配给每个线程,每个线程可以simultaneoulsy被执行来实现的概念。还有在这种情况下没有调度因为每个线程有独立的资源都专用于它。
但我recenetly读它的地方,我可以做多线程单处理器系统上也是如此。
这是对的吗?如果是,则是单处理器和多处理器系统之间的区别?

I have always followed the concept that multithreading can only be implemented on multiple processors system where there are more than one processor to be assigned to each thread and each thread can be executed simultaneoulsy. There is no scheduling in this case as each of the thread has separate resources all dedicated to it. But I recenetly read it somewhere that I can do multithreading on single processor system as well. Is it correct? and if yes then what is the difference between single processor and multiple processor systems?

推荐答案

当然,它可以在单处理器系统上进行,而事实上它更容易的方式。它的工作方式是运行多个进程相同的 - 内核,通过定时器中断或其他类似的机制,将挂起之一,其保存机器状态,并取代了由previously保存的另一种状态 - 唯一的区别是相同的进程共享相同的虚拟存储器空间的两个线程,使得任务切换更加高效。

Of course it can be done on a single-processor system, and in fact it's much easier that way. It works the same way as running multiple processes -- the kernel, via a timer interrupt or other similar mechanism, suspends one, saving its machine state, and replacing that by the previously-saved state of another -- the only difference being that two threads of the same process share the same virtual memory space, making the task-switch much more efficient.

多线程在多处理器系统实际上是要困难得多,因为你必须同时访问的问题,从多个CPU /内存的核心,和所有引申出来的那讨厌的内存同步的问题。

Multi-threading on multi-processor systems is actually much more difficult, since you have issues of simultaneous access to memory from multiple cpus/cores, and all the nasty memory synchronization issues that arise out of that.

这篇关于可以多线程单处理器系统上实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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