内置的多线程支持意味着什么?

发布于 2024-11-27 23:41:24 字数 236 浏览 1 评论 0原文

Java 提供了对多线程编程的内置支持。

这就是我的书所说的。我也可以用 C、C++ 进行多线程编程。那么它们也提供对多线程的内置支持吗?

内置的多线程支持意味着什么?它不是真正提供多线程支持的操作系统吗?

有没有不支持多线程的编程语言?如果是这样为什么? (我问这个问题是因为,如果操作系统提供对多线程的支持,那么为什么我们不能在该操作系统支持的所有语言上进行多线程编程?)

Java provides built-in support for multithreaded programming.

That is what my book says. I can do multithreaded programming in C, C++ also. So do they also provide built-in support for multithreading?

What does built in support for multithreading mean? Isn't it the OS that ACTUALLY provides support for multithreading?

Are there any programming languages that cannot support multithreading? If so why? (I am asking this question because, if the OS provides support for multithreading then why cant we do multithreaded programming on all languages that are supported on that OS?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

喜你已久 2024-12-04 23:41:24

问题是多线程的语言支持与库支持之一。

Java 使用关键字synchronized 在对象上放置锁是一种语言级构造。此外,Object 上的内置方法(wait、notify、notifyAll)直接在运行时实现。

关于语言是否应该通过关键字、语言结构和核心数据类型实现线程与在库中拥有所有线程功能存在一些争论。

一篇支持语言级线程有益的观点的研究论文是相对著名的 http://www.hpl.hp.com/personal/Hans_Boehm/misc_slides/pldi05_threads.pdf

理论上,任何基于 C 运行时构建的语言都可以访问 pthread 等库,并且任何在 JVM 上运行的语言都可以使用这些线程。简而言之,所有可以使用库(并且具有函数指针概念)的语言确实可以进行多线程处理。

The issue is one of language-support vs. library support for multithreading.

Java's use of the keyword synchronized for placing locks on objects is a language-level construct. Also the built-in methods on Object (wait, notify, notifyAll) are implemented directly in runtime.

There is a bit of a debate regarding whether languages should implement threading though keywords and language structures and core data types vs. having all thread capabilities in the library.

A research paper espousing the view that language-level threading is beneficial is the relatively famous http://www.hpl.hp.com/personal/Hans_Boehm/misc_slides/pldi05_threads.pdf.

In theory, any language built on a C runtime can access a library such as pthreads, and any language running on a JVM can use those threads. In short all languages that can use a library (and have the notion of function pointers) can indeed do multithreading.

小清晰的声音 2024-12-04 23:41:24

我相信他们的意思是Java有内置的关键字,例如volatilesynchronized关键字,以使多线程更容易,并且该库已经提供了线程类,因此您不需要第三方库。

I believe they mean that Java has keywords like volatile and synchronized keyword built-in, to make multithreading easier, and that the library already provides threading classes so you don't need a 3rd party library.

请帮我爱他 2024-12-04 23:41:24

语言需要构造来创建和销毁线程,而操作系统又需要向语言提供这种行为。

例外的是 Java 绿色线程,它们根本不是真正的线程,我认为与 Erlang 类似。

一种不支持线程的语言,例如 QBasic 在 DOS 中实现的 Basic。基本应该是基本,因此线程和进程是高级功能,在语言意图中是非生产性的。

The language needs constructs to create and destroy threads, and in turn the OS needs to provide this behaviour to the language.

Exception being Java Green Threads that aren't real threads at all, similarly with Erlang I think.

A language without threading support, say Basic implemented by QBasic in DOS. Basic is supposed to be basic so threads and processes are advanced features that are non-productive in the languages intent.

夏末 2024-12-04 23:41:24

C 和 C++ 作为一种语言没有机制可以:

  1. 启动线程
  2. 声明互斥体、信号量等

不是语言规范的一部分。然而,每个主要操作系统上都存在这样的功能。与 Java 不同,这些工具在不同的操作系统上是不同的:Linux、OS X 和其他 UNIX 衍生版本上的 pthread,Windows 上的 CreateThread,实时操作系统上的另一个 API。

Java 有一个针对Threadsynchronized 块和方法、“notify”、“wait”作为核心Object 等部分的语言定义,这使得该语言能够正确理解多线程。

C and C++ as a language have no mechanism to:

  1. Start a thread
  2. Declare a mutex, semaphore, etc
  3. etc

This is not part of the language specification. However, such facilities exist on every major operating system. Unlike in Java, these facilities are different on different operating systems: pthread on Linux, OS X and other UNIX-derivatives, CreateThread on Windows, another API on real-time operating systems.

Java has a language definition for Thread, synchronized blocks and methods, 'notify' 'wait' as part of the core Object and the like, which makes the language proper understand multithreading.

半世蒼涼 2024-12-04 23:41:24

这意味着该语言的运行时中有一些功能可以模拟线程的概念以及与之相关的所有功能,例如提供同步。幕后发生的事情取决于语言实现者……他们可以选择使用本机操作系统线程,也可能会伪造它。

不支持它的语言可能是 VB6(至少不是原生的,IIRC)

It means that there is functionality in the language's runtime that models the concepts of threads and all that goes with that such as providing synchronisation. What happens behind the scenes is up to the languages implementors... they could choose to use native OS threading or they might fake it.

A language that doesn't support it could be VB6 (at least not natively, IIRC)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文