Detached Threads (pthreads) | C Programming Tutorial

  Рет қаралды 5,444

Portfolio Courses

Portfolio Courses

Күн бұрын

Пікірлер: 23
@erendemirer1
@erendemirer1 11 ай бұрын
You're a great teacher. When I need to learn about subjects I don't know, I find myself here. Greets from Ecole 42, thank you!
@dinispetrukha4382
@dinispetrukha4382 9 ай бұрын
42 Lisbon here! :)
@giulianobortolassi573
@giulianobortolassi573 9 ай бұрын
Well these videos are gold! I am just impressed why it has so few likes! it deserve way more!!
@ironudjin
@ironudjin 4 күн бұрын
Accessing global variable from the main program and thread is unsafe. Reading and writing into it has to be protected by mutex or an atomic variable has to be used.
@bernhardkneer5393
@bernhardkneer5393 Жыл бұрын
Hi, nice video but I would have a question to the detached thread. My understanding is that when the thread is detached from the main thread it runs independently. But what happens when main ends. When will the thread end as it is running in an endless loop? Will it get notified by the main thread. In addition the thread is using the file pointer to write the log file. As this file is close by the main thread before it ends I would assume that the thread would crash when it tries to write the next timestamp. Or did I miss something? Thanks a lot.
@Redditard
@Redditard 11 ай бұрын
I am sure mutexes should be used here
@tiankong90
@tiankong90 2 ай бұрын
I am also confused. I hope anyone can give some advice.
@vicsteiner
@vicsteiner 6 ай бұрын
Another nice video! Interesting that the log is not a log of the event of a new incident but just the status at a specific timestamp. So I can enter more than one incident in between the logger executions. I was curious if things like garbage collection could work using detached threads too?
@mastermax7777
@mastermax7777 Жыл бұрын
Hi Teacher, what is the meaning of "struct tm *tm" ? how can a struct have two variable names. 9:00 . I am confused, thank you
@jdeleca
@jdeleca 10 ай бұрын
Those are not two variables names, he is naming the variable exactly as the struct, because the struct is called: tm, so he first writes the type of the variable: struct tm and then the variable: tm, together will be: *struct tm tm*
@dzeno7370
@dzeno7370 2 жыл бұрын
How is that you put "&logger" inside pthread_create function for detached threads, but on your previous videos there is no ampersand in front of callback functions inside pthread_create (i.e. function "deposit" inside "Race Conditions Explained With An Example" video, and function "computation" inside "Introduction To Threads (pthreads)" video ??
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
This is a really great question! 🙂 In my experience both function_name and &function_name will give you the memory address (pointer) of the function. So I actually think the answer is that "it doesn't matter", and that in the one video I just did it differently for no real reason. I am trying to find some official documentation to verify this, but I'm 99% sure this is the case. For example in the code below we will get the same memory address output: #include void *func() { printf("func! "); } int main() { func(); printf("%p ", func); printf("%p ", &func); return 0; }
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
But to further clarify... in retrospect I shouldn't have used the & operator in this example given that it's not really necessary.
@dzeno7370
@dzeno7370 2 жыл бұрын
@@PortfolioCourses I was thinking the same, but was not sure because that "&" usually plays a big role when dealing with pointers and adresses. Nevertheless, considering that you have more expirience than I do, I will take you asswer as a correct one. Thank you for for a quick response and also great videos.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
It’s interesting I’ve found very official examples online for reputable sources that do it both ways! The compiler will likely just do the same thing no matter what, so it doesn’t matter too much either way. :-)
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
One more update... I found an official answer, they are in fact the same: stackoverflow.com/a/6293570. Though this question actually gave me two new ideas for videos, as I would like to cover this, and the difference between array and &array (where it turns out there actually is a difference).
@trocandobytes
@trocandobytes Жыл бұрын
Hi! Thank you for share your knowledge ! So, do you put the char timestamp[256] declaration inside the while loop redeclaring the array again and again... This can cause a bug by running for a long time ?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Great question! :-) Just to be clear with how it's working, it's *not* the case that if the loop runs 100 times we have 100 char arrays timestamp that exist simultaneously as a result. At any one time we will only have one char array timestamp that exists. In theory every time the loop runs we get a "new" char array timestamp but the "old" one from the last loop iteration is no longer there. The compiler may do some optimizations though and re-use the same memory, I'm not sure we would have to print out the memory address of the char array with each loop iteration to check this. But anyways, because only one array will ever exist at a time, it shouldn't cause a bug. :-)
@trocandobytes
@trocandobytes Жыл бұрын
@@PortfolioCourses I see, thank you for answering !
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You’re welcome! :-)
@ValliNayagamChokkalingam
@ValliNayagamChokkalingam Жыл бұрын
Awesome!
@RoockYou
@RoockYou 2 жыл бұрын
thaanks you so much man
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome! :-D
Comma Operator (And When To Use It) | C Programming Tutorial
13:36
Portfolio Courses
Рет қаралды 2,3 М.
C programming practice session :Easy understanding(part-1)
42:02
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
Don't constexpr All the Things - David Sankel [CppNow 2021]
1:00:47
Function Pointers | C Programming Tutorial
18:31
Portfolio Courses
Рет қаралды 70 М.
Introduction To Threads (pthreads) | C Programming Tutorial
13:39
Portfolio Courses
Рет қаралды 115 М.
Fork and Pthreads - A Guide To Get You Started with Multiprocessing
17:28
Condition variables in C
18:57
CodeVault
Рет қаралды 100 М.
Mutex Introduction (pthreads) | C Programming Tutorial
10:19
Portfolio Courses
Рет қаралды 24 М.
you will never ask about pointers again after watching this video
8:03
Mutex Synchronization in Linux with Pthreads
25:07
Brian Fraser
Рет қаралды 161 М.
why are switch statements so HECKIN fast?
11:03
Low Level
Рет қаралды 437 М.
Binary File Access Introduction | C Programming Example
16:17
Portfolio Courses
Рет қаралды 28 М.