How to use realloc in C
11:56
Жыл бұрын
Convert string to Lowercase in C
9:49
Don't make the same mistake I did!
10:02
Format and parse datetime in C
17:41
What does fork() actually return?
7:13
Sharing functions between files in C
9:00
Пікірлер
@abolevi3768
@abolevi3768 4 сағат бұрын
your video is 4 years old but I really appreciate your help
@cesaltinofelix
@cesaltinofelix 7 сағат бұрын
i was here
@georgesaman692
@georgesaman692 23 сағат бұрын
Incredible. I've learned so much from you! appreciate all your efforts!
@Anduuu077
@Anduuu077 Күн бұрын
very good video adn explanation
@sidahmed2.044
@sidahmed2.044 2 күн бұрын
Based guy
@khomo12
@khomo12 2 күн бұрын
Nice! Thank you!
@engmoatazabdelhalim7343
@engmoatazabdelhalim7343 2 күн бұрын
Thanks a lot
@drdriven
@drdriven 3 күн бұрын
literal saviour
@bunnysupreme74
@bunnysupreme74 3 күн бұрын
When you used wnohang, the parent process finished before the child processes. But wouldnt that cause zombie processes, since the parent process is responsible for terminating its child processes?
@nadiatavarez8454
@nadiatavarez8454 4 күн бұрын
I have never seen someone explain programming this good! Nice work! If there is ever a chance u do videos for c++, please do!
@ismbks
@ismbks 4 күн бұрын
legit everyone at my school recommends to watch this series, crazy work
@Varelinski
@Varelinski 5 күн бұрын
1:13 I didn't even know you could initialize struct values like that...
@ic_1234
@ic_1234 6 күн бұрын
thanks man!!
@stack.1
@stack.1 6 күн бұрын
For accessing variables accross threads shouldn't that be limited to stuff created on heap?
@stack.1
@stack.1 6 күн бұрын
I think if you're using Cmake the dependent libraries options are automatically set for compile/link
@cesaltinofelix
@cesaltinofelix 7 күн бұрын
i was here
@散华-l9m
@散华-l9m 7 күн бұрын
19:31 thread works only when it gets a task, otherwise wait and release lock
@AlfadelAbdAlla-y8g
@AlfadelAbdAlla-y8g 8 күн бұрын
CAN YOU DO A VIDEO FOR POINTERS
@散华-l9m
@散华-l9m 8 күн бұрын
mutex here to protect the shared memory (Task queue) 14:36
@散华-l9m
@散华-l9m 8 күн бұрын
also make sure 13:21 each thread would not executeTask when they have no task! (found ==1)
@散华-l9m
@散华-l9m 8 күн бұрын
okok after one thread got the task, the release the lock for other threads to get the tasks. But at the same time, we want every tasks immediately execute after they got the task. So execute Task should be available at any time. (even if 2 or more thread got their tasks.)
@AmirMohammadCheshmBerah
@AmirMohammadCheshmBerah 8 күн бұрын
in first method actually we using deque you can't iterate queue backward
@KH-en1yr
@KH-en1yr 10 күн бұрын
did you make a separate playlist/course of such functions? if so, please let me know its name.
@naboulsikhalid7763
@naboulsikhalid7763 10 күн бұрын
thank you for making it simple to graspe.
@MrSomethingdark
@MrSomethingdark 12 күн бұрын
Hey CodeVault, thank you for giving me back my sanity. You and portfolio courses and so many lucid people online really serve as a nice place to refresh my mind after taking an online course for a certificate. Thanks a lot. I need this tutorial. Stay frosty!
@AdeBorris
@AdeBorris 12 күн бұрын
Great analysis, thank you! I have a quick question: I have a SafePal wallet with USDT, and I have the seed phrase. (alarm fetch churn bridge exercise tape speak race clerk couch crater letter). Could you explain how to move them to Binance?
@nandorboda8049
@nandorboda8049 12 күн бұрын
7:15 It's important to notice that bytes are in reveresed order at each element. It's called small endian. For example if there wouldn't be small endian arrangement, the first element, 16, should be represented as { 00 00 00 00 00 00 00 10 }. Firstly it's not very noticeable in the case if you used 16,31,32,65 or other numbers that can be represented as a byte but if you exceed that byte, the small endian arrangement will be noticable. Ex. (unsigned) 256 would be { 01 00 } but with small endian representation it's { 00 01 }. So this program is only good for these small numbers.
@clarencelucius9085
@clarencelucius9085 13 күн бұрын
So it's a pointer to a pointer?
@DmitryMyasnikov
@DmitryMyasnikov 13 күн бұрын
Thanks!
@Stoh
@Stoh 14 күн бұрын
Phenomenal video, thank you.
@Kingdomprogrammer
@Kingdomprogrammer 14 күн бұрын
I made a nice improvements to this code. maybe wanna have a look? I set a max size of the car's fuel tank and made sure the fuel tank was full before the car leaves the filling station and also made the the filling station only signal the car only when there's enough for the car(i.e fuel > 40) at least to help improve understanding
@Kingdomprogrammer
@Kingdomprogrammer 14 күн бұрын
in the fuel filling function, if you don't sleep after a single loop, it completes all 5 iterations before it signals the car routine thread. why's that so?? the signal is in the for loop. and since the code executes for each iterations.
@stack.1
@stack.1 15 күн бұрын
@stack.1
@stack.1 15 күн бұрын
so we can do execlp("bash", "bash", "-c", "ping ....") ; ?
@stack.1
@stack.1 15 күн бұрын
ok yeah we can
@KH-en1yr
@KH-en1yr 15 күн бұрын
what if we don't know the count?
@CodeVault
@CodeVault 13 күн бұрын
You can also pass a special value (usually NULL) at the end to signify the end of the arguments
@ree-101
@ree-101 15 күн бұрын
brilliant explanation. not only did you explain how to use it, but also what happens to the code in the background as well. thank you so much
@n_stre
@n_stre 15 күн бұрын
Thanks Sergiu! Would love to see your take on arena allocators in C
@CodeVault
@CodeVault 15 күн бұрын
I haven't implemented one but I did start reading on it. Honestly it seems like a better idea than allocating/reallocating/deallocating every little thing in the project. So many optimizations could be done this way
@MertUnaldStudent
@MertUnaldStudent 16 күн бұрын
hello , why in this case the child process doesn't have 0 as process id ? . Thank you
@CodeVault
@CodeVault 15 күн бұрын
The child process never has id 0. What was 0 was the return value of fork() which doesn't represent the process id in the child process. fork() returns 0 in the child process and the child's process id in the parent process.
@rajivkumarkale
@rajivkumarkale 16 күн бұрын
Race conditions can occur in both single-core and multi-core systems, though they are more common and likely to cause issues in multi-core systems. Here’s why: Definition of a Race Condition: A race condition happens when multiple threads or processes access shared data or resources at the same time, and the outcome depends on the order or timing of their execution. Without proper synchronization, these concurrent accesses can lead to unpredictable and incorrect behavior. Multi-Core Processors: In multi-core systems, different cores can execute threads or processes truly in parallel. This means that if two threads are accessing the same variable, one thread may read the value before the other has completed its write operation, leading to inconsistent results. The parallel nature of multi-core systems amplifies the risk of race conditions, especially if synchronization mechanisms (like locks or semaphores) are not used. Single-Core Processors: Although single-core processors execute threads in a time-sliced manner rather than truly in parallel, race conditions can still occur here. This is because the operating system can switch between threads at any time, interrupting one thread in the middle of an operation and allowing another to execute. If this interrupted thread was working on shared data, a race condition can still result, despite the lack of true parallel execution. In short, race conditions are possible in both single-core and multi-core systems, but multi-core systems make race conditions more apparent and challenging to avoid due to true concurrent execution.
@CodeVault
@CodeVault 15 күн бұрын
That's exactly right! I misspoked when I said that they can't happen on single-core systems. Sorry about that
@zikocult
@zikocult 16 күн бұрын
if i don't want to declare x as global, how can i pass the value of x to the function? when i try this "sa.sa_handler = &handle_sigusr1(x);", give me an error. The prototype of my function was void "handle_sigusr1(int x);"
@CodeVault
@CodeVault 15 күн бұрын
Since the handler is called on signal there isn't an easy way to do it without relying on something that is global
@zikocult
@zikocult 15 күн бұрын
@@CodeVault Thanks :)
@gabriela-807
@gabriela-807 17 күн бұрын
I understood what you meant, but I didn't understand how each thread sees the correct index just because it allocated a space in memory. Doesn't each thread, when it starts and enters the function, run the risk of accessing the same index? Why didn't you use the mutex in this case? Excuse my English, I'm using the translator
@CodeVault
@CodeVault 15 күн бұрын
Not really, each thread gets created with a different input index therefore there is not issue accessing the same index. Actually, in this case it wouldn't even matter since we are only reading the values. Parallel reading of data is fine, only when writing do race conditions become a problem
@添野祥子
@添野祥子 17 күн бұрын
ありがとうございます!
@CodeVault
@CodeVault 15 күн бұрын
ご寄付ありがとうございます!
@DragonDreamer-b9o
@DragonDreamer-b9o 17 күн бұрын
amazing, I cant find any other platform that breaks it down like this to help me understand, thank you!
@christiansaab2044
@christiansaab2044 19 күн бұрын
bro just saved me litteraly 16 hours of lab sessions in around 5 videos
@yoram9692
@yoram9692 19 күн бұрын
Awesome video bro you are bright
@HimanshuSharma-b3q3u
@HimanshuSharma-b3q3u 19 күн бұрын
hey @CodeVault , your linked site is not working anymore. is it only for me, or its offline in general?
@CodeVault
@CodeVault 15 күн бұрын
It wasn't working for a bit. Now it should. Although, it's weirdly developed and needs access to store data to LocalStorage, make sure you try other browsers as well. Some come with that disabled
@elevatordude8085
@elevatordude8085 19 күн бұрын
thank you sir
@AbdelrahmanAzmi
@AbdelrahmanAzmi 20 күн бұрын
your video is awesome bro, thank you so much!
@telwen1566
@telwen1566 20 күн бұрын
Thanks ^^
@xinwu5427
@xinwu5427 20 күн бұрын
There is still an infinite loop in `startThread`, which never returns. Any solutions for this?
@CodeVault
@CodeVault 20 күн бұрын
You can listen to a signal or, on a different thread, have a scanf that, when entering an option, closes the whole process
@xinwu5427
@xinwu5427 20 күн бұрын
@@CodeVault thanks! Below `submitTask_done` is used to signal that all tasks have been submitted. Then, if `taskCount` equals 0 in the infinite loop in `startThread`, it will return NULL. ``` --- Thread_Pools_with_function_pointers_in_C.c 2024-11-02 15:33:30.508724954 +0100 +++ newer_version.c 2024-11-02 15:37:35.525364984 +0100 @@ -14,6 +14,7 @@ Task taskQueue[256]; int taskCount = 0; +int submitTask_done = 0; pthread_mutex_t mutexQueue; pthread_cond_t condQueue; @@ -51,6 +52,10 @@ pthread_mutex_lock(&mutexQueue); while (taskCount == 0) { + if (submitTask_done) { + pthread_mutex_unlock(&mutexQueue); + return NULL; + } pthread_cond_wait(&condQueue, &mutexQueue); } @@ -85,6 +90,7 @@ }; submitTask(t); } + submitTask_done = 1; for (i = 0; i < THREAD_NUM; i++) { if (pthread_join(th[i], NULL) != 0) { ```