Subject. It is clear that there are many good and different libraries for parallelizing programs into threads and tasks. And how to write a library for multi-threading on bare C? What is needed for this (just a plan, step by step)? What to read about this?
Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants of LEQADA , Vladimir Glinskikh , Bald , Yuri Glushenkov , Kromster 8 December '15 at 4:54 .
The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .
1 answer
You still have to deal with libraries. The OS API for which you write this is the library. And any variety of other libraries for multithreading is just wrappers over the API. And also in C itself there is no support for multithreading. So the answer does not seem to be to write multi-threaded code on bare C. Even in C ++, the new standard implements multi-threading in the standard library, and not in the language itself.
If you want to write multi-threaded code, then for example for * nix systems you need to learn the pthread library.
Well, for Windows, you need to read the dock on the windows API which is responsible for multithreading.
- @Roman Goriachevskiy man 2 clone @Siarshai well, for example bsvi.ru/protopotoki-protothreads (although it’s not streams at all ...) - alexlz
- @alexlz well, for that matter, the windows API is also written in pure C and pthread is written on it. And while they use the capabilities of the operating system for their implementation. And under the link there is a code for microcontrollers and this library seems to represent a mini-OS for controllers in which there are threads, as it were. Using this library, you can write supposedly multi-threaded code, but there it is not clear when and how execution switches from stream to stream and there will be no real multithreading on a multi-core controller. - Roman Goriachevskiy pm
- @Roman Goriachevskiy is not a protothread - it is rather coroutines than threads. But clone is a kernel call that refers, of course, to libc, but no more. - alexlz
- @alexlz: in any case, if I don’t change my memory, there are no threads in standard C, so I’ll have to use OS-specific tools. - VladD
- In C, of course, there are no threads. And clone is a very Linux-specific challenge. Anyway, the languages in which there are threads, years are not so much. Fifty years from strength (PL / I, type TASK) - alexlz