pphanireddy
pphanireddy

Reputation: 1129

What does built in support for multithreading mean?

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?)

Upvotes: 4

Views: 2252

Answers (5)

Ray Toal
Ray Toal

Reputation: 88468

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.

Upvotes: 4

James
James

Reputation: 9278

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)

Upvotes: 0

Yann Ramin
Yann Ramin

Reputation: 33197

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.

Upvotes: 0

Steve-o
Steve-o

Reputation: 12866

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.

Upvotes: 0

user541686
user541686

Reputation: 210755

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.

Upvotes: 1

Related Questions