Static Variable Is Thread Safe OR Not

preview_player
Показать описание
JOIN ME
—————

COMPLETE PLAYLIST
————————————

INTERVIEW PLAYLIST
————————————

QUICK SHORT VIDEOS
————————————-

In this video we will see the live example that how static variables are not thread safe.

#programming #cppprogramming #cprogramming
Рекомендации по теме
Комментарии
Автор

You are doing a great job! To solve this particular issue, it seems like the easiest solution is to use an atomic library and define the variable "s" as atomic. This way, the mutex is no longer necessary. Thank you and good luck!

markusbuchholz
Автор

@CppNuts, please make a video explaining the concept of Semaphores in C++! You are the best explaining difficult concepts!

japusinbibe
Автор

That's why strtok_r should be used in favor of strtok for multithreaded code. strtok has a static variable. This is just an example, there are more functions which are not thread-safe.

ArjanvanVught
Автор

map<int, int> m;
m[1]=1;
m[2]=2;
m[3]=3;

m.erase(m.end());

for(auto ele : m){
cout<< ele.first<<" " <<ele.second<<endl;

}
Output is
1 1
3 3

But when i do
m.erase(--m.end());

Output is
1 1
2 2

Can you plz varify and tell me whats happening here

sachinkiragi
Автор

@CppNuts, at time 5:32, if thread1 is suspended right after m.unlock(), and thread2 increments s for some time, then doesn't thread1 print s as
I mean it is not guaranteed to print by thread1.

Can you please correct me if I'm wrong ?

ChaduvukondiFirst-lgvt
Автор

how to increase our cpp skills?? currently working only on c programming. want to switch to cpp position. Please share your thoughts.

sharathkumar
Автор

hey cpp nuts you didn't do video on vptr and vtable.

sharathkumar