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!
@dinispetrukha43829 ай бұрын
42 Lisbon here! :)
@giulianobortolassi5739 ай бұрын
Well these videos are gold! I am just impressed why it has so few likes! it deserve way more!!
@ironudjin4 күн бұрын
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 Жыл бұрын
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.
@Redditard11 ай бұрын
I am sure mutexes should be used here
@tiankong902 ай бұрын
I am also confused. I hope anyone can give some advice.
@vicsteiner6 ай бұрын
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 Жыл бұрын
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
@jdeleca10 ай бұрын
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*
@dzeno73702 жыл бұрын
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 ??
@PortfolioCourses2 жыл бұрын
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; }
@PortfolioCourses2 жыл бұрын
But to further clarify... in retrospect I shouldn't have used the & operator in this example given that it's not really necessary.
@dzeno73702 жыл бұрын
@@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.
@PortfolioCourses2 жыл бұрын
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. :-)
@PortfolioCourses2 жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@@PortfolioCourses I see, thank you for answering !