C is a language that runs on one thread by default, which means that the code will only run one instruction at a time. In some cases you'll need to...
For further actions, you may consider blocking this person and/or reporting abuse
pthread is outdated since availability of C11 which introduced standard threading in C. The header files is
<threads.h>
with functions likethrd_create
.The standard functions for threading, conditions, and signalling, provide guarantees that pthreads cannot.
I have my answers,
threads.h
is better to use even if it's not POSIX (stackoverflow.com/a/9377007)pthread.h
is POSIX compliant,threads.h
isn't.But sure you can use it, it's implemented in linux and freeBSD kernels.
But
threads.h
is C11 compliant so by now ALL compilers have support for C11 at least for the three major ones:MSVC
GCC
CLANG
Yup, seems nice, their is just a lack of documentation, I wanted to know what did it really does.
You can find documentation here: en.cppreference.com/w/c/thread
Well, it's the C libraries for two of those platforms that are supposed to implement
threads.h
(even though I'm pretty sure glibc doesn't), although I'm not sure what Windows does.It's not the kernels, it's the C libraries. You can have a kernel installed and not be able to do anything without a C library.
Thanks Nathanael! Nice starter article on pthreads :)
For the curious, Lawrence Livermore National Laboratory have this article with more background and examples of why you might use the various features available in pthreads: computing.llnl.gov/tutorials/pthre...
It's also a good idea to make sure you are using thread-safe library functions, here's a nice SO question and answer: stackoverflow.com/questions/125957...
Enjoy your full control of the CPU!
Glab that you enjoyed it!
I'm starting to understand a lot about pure Computer Science since I got some courses about the theory of operating systems. It's so fascinating to learn how things really works beyond the compilers and why things are like that in programming languages!
Can you suggest that courses pls.
For the theory of operating systems, I see this subject at my school (engineering school), but for programming languages I heard that Engineering a Compiler is very great when starting in this domain.
The Dragon Book is very good but much more advanced.
Thank god for every C-related article here (for us, who have interest in low-level programming). Thanks, Nathanael!
C can be a very scary language at first but it's so captivating, I'm happy that you enjoyed reading this article 😄
Hey, recently I worked with the C++ standard thread library and made a series about it, where I've talked about the mutexes and locks. I hope you'll find it useful. dev.to/shreyosghosh/series/20850
Why can't you use a
for
loop?for( i = 0; i < 5; i++ )
You can and should do a for loop. It's been 1 year since I did this article, I think it's time to rewrite it with my current knowledge :)