![]() |
CITS2002 Systems Programming |
← prev | next → | ![]() |
![]() |
|||
Some definitionsThreads are a programming abstraction designed to allow programmers to control concurrency and asynchrony within a program.In some programming languages, like Java, threads are "first-class citizens" - they are part of the language specification itself. For others languages, like C and C++, threads have not traditionally been part of the language specification, and were implemented as a library of functions linked with, and called by, a program. This changed with C11 which now defines portable threads as part of its standard. The differences between having threads "in the language" and threads "as a library" are subtle and important. For example, a C compiler need not take into account thread control (leaving that to the programmer), while a Java compiler must. Analogously, we see that C enables fine-grain control of memory mangement, while Java strictly defines it as part of its standard. In the library case, it is possible to choose from different thread libraries to provide different semantics. In contrast, (all conforming) Java and C11 programs are required to support their single thread model and API. What is a thread?We'll informally define threads within a program to include three things:
This definition corresponds roughly to the C language model of sequential execution and variable scoping. Operating systems are still significantly written in C and, thus, thread libraries for C are easiest to understand and implement when they conform to a familiar model. And why?Threads provide two important opportunities:
CITS2002 Systems Programming, Lecture 20, p2, 9th October 2023.
|