Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C multi-threading origin

In my copy of C Programming Language (aka: K&R), there seems no mention of multithreading. Is the book less complete than I imagined? Did multithreading emerge after it was written? Am I thinking about this the wrong way?

Where does the concept of multithreading fit into the C world?


Edit: I think my original question have been:

  • you can write anything in C
  • multithreading exists
  • you cannot write multithreading in C <-- logical contradiction

What accounts for this contradiction? Where's the origin of multithreading? If POSIX, then what is POSIX written in if not C? A form of assembly that is inaccessible to C?

like image 419
Dinah Avatar asked Apr 21 '09 21:04

Dinah


1 Answers

C is a pretty low level language. Support for threads in a typical C program comes from the OS, not from the C runtime - if your environment doesn't support threads, then you'll have to implement them yourself, find a library that does it, or do without threads. This is in contrast to a language like Java, where the runtime environment provides many services that are guaranteed to be available to Java programs whether or not the underlying OS supports them in the manner that the Java platform exposes.

Now, having said that, I'm pretty sure that when the first edition of K&R was published, Unix did not support threads. Since C was first implemented as a systems language for the Unix environment, it's not surprising that it has no native thread support.

If you're writing code for a Unix like environment, look for POSIX threads if you need a well supported API for implementing multithreaded programs in C.

like image 110
Ori Pessach Avatar answered Oct 05 '22 23:10

Ori Pessach