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

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

问题描述

我一直遵循这样的概念,即多线程只能在多处理器系统上实现,其中每个线程分配一个以上的处理器,并且每个线程可以同时执行.在这种情况下没有调度,因为每个线程都有专用于它的单独资源.但我最近在某处读到它,我也可以在单处理器系统上进行多线程处理.这是正确的吗?如果是,那么单处理器和多处理器系统之间有什么区别?

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?

推荐答案

当然,它可以在单处理器系统上完成,而且实际上那样更容易.它的工作方式与运行多个进程的方式相同——内核通过定时器中断或其他类似机制暂停一个进程,保存其机器状态,并用之前保存的另一个状态替换它——唯一的区别是两个同一进程的线程共享相同的虚拟内存空间,使得任务切换更加高效.

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天全站免登陆