超线程编程语言
超线程可以用哪些语言来实现? 它只是面向对象系统的一部分还是可以用 C 实现?
谢谢。
What languages can hyper-threading be implemented in? Is it only part of Object Oriented systems or can it be implemented in C?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
任何支持线程的语言和运行时都将支持超线程。
超线程是一种在多个线程之间多路复用一个CPU的方法——只有一个真正的CPU,但它对操作系统来说是可见的两个CPU,因此可以在其上调度两个线程。 一个线程上的 CPU 中的任何停顿(例如等待内存、长时间的 FPU 操作等)都会允许 CPU 执行另一线程的代码。
有关超线程的更多信息,请访问 Wikipedia。
Any language and runtime that supports threads will support hyperthreading.
Hyper-threading is a way of multiplexing a CPU between multiple threads - there is only one real CPU but it is visible to the operating system as two CPU's, and thus two threads can be scheduled on it. Any stalls in the CPU on one thread (like waiting on memory, long FPU operations, etc.), allow the CPU to execute code from the other thread.
More info on hyper-threading at Wikipedia.
超线程在很大程度上与系统中拥有更多处理器相同。 即使您的语言不支持线程,仍然可以使您的程序产生自身的另一个副本或产生工作进程,这些进程将(如果操作系统支持它)在可用处理器上进行平衡。
您需要查找您的语言的线程支持,但要注意线程很容易使您的程序复杂化,并且可能导致难以发现错误,因为代码可以异步执行。
所以你的问题的答案是“可能,但这取决于”。
至于您的其他问题,您可以根据您的运行时和编译器支持轻松地在 C 中再次实现多个线程。 例如,OpenMP 扩展 http://en.wikipedia.org/wiki/OpenMP 可能很有用为你。
Hyperthreading is for the most part the same as having more processors in a system. Even if your language does not support threads it is still possible to make your program spawn another copy of itself or spawn worker processes that will (if the operating systems supports it) be balanced over the available processors.
You need to look up thread support for your language but beware that threads can easily complicate your program and might result in hard to find bugs since the code can be executed asynchronously.
So the answer to your question is 'probably, but it depends'.
As for your other question you can easily implement multiple threads in C again depending on your runtime and compiler support. For example the OpenMP extensions http://en.wikipedia.org/wiki/OpenMP could be useful for you.