Igor🇺🇦
and create a mutex for each thread, it doesnt matter the order, just that each thread has its own mutex
You don't create mutex per thread. To write to a variable for example you need to do something like : GetMutex() Write() ReleaseMutex()
Andrew
I get so one mutex for each criitical variable?
Andrew
Thank you very much, i have exam on this things soon
Igor🇺🇦
Thank you very much, i have exam on this things soon
You don't "get" mutex for path. You wrap calls to shared resource with get /release mutex. This ensures that only one thread can write at the same time
Andrew
Yes i know this, i didnt understand only wich mutex variable to use if i have more threads or more variables
Alex
Yes i know this, i didnt understand only wich mutex variable to use if i have more threads or more variables
you can`t modify and read same non-atomic variable in several threads. Thus you should protect these vars using mutex. you can use one mutex for one var, or one mutex for one struct/several vars. this is called granularity. code for writing/reading these vars is called critical section. so each critical section should be protected by mutex
Andrew
So if i have 2 critical variables in the function i have to use 2 mutex variables like Getmutex(1) Edit var1 Release mutex(1) Getmutex(2) Edit var2 Release mutex(2) ?
Andrew
But its counter intutive, how do the program knows to wich mutex variables is related to the critical variable, even before being edited?
Alex
variables are not related to the mutex, you just create critical section using mutex. reading/writing these vars should be inside this critical section
Andrew
I understand thanks, so basically the rule is one critical section for one critical value
Alex
Alex
for example you have struct foo { int var1; int var2; mutex_t m; } so you acquire mutex each time to read/write struct fields foo f; f.m.lock(); f.var1 = 4; f.var2 = 5; f.m.unlock(); you have one mutex for two vars
Andrew
Because a struct can be considered as a single variable?
Alex
Because a struct can be considered as a single variable?
no.you can do the same for int var1; int var2; but in this case, its harder to keep in mind your mutex m is related to those vars
Alex
you can also have this code: struct foo { int var1; mutex_t m_var1; int var2; mutex_t m_var2; } its up to you
Andrew
I dont get, why in a struct you can use only one mutex? If you have 100 variables in a struct you still can use only 1 mutex?
Andrew
But thanks i have things more clear now
YVEF
I don't understand how reverse iterators help you, but if it does what you want OK, I guess...
in other words. I have byte* arr1 = new byte[n]{ 1, 2, 3, 4, 2, 3, 5 }; byte* arr2 = new byte[m] { 2, 3}; std::magic(arr1, arr1 + n, arr2, arr2 + m) => byte* ptr_result which is pointing to second "2" (index == 4); what's I need
Omkar77
Guys ... C++ is so hard to use in VSC
Duncan
Guys ... C++ is so hard to use in VSC
No it's very easy just install C++ extensions
Omkar77
No it's very easy just install C++ extensions
Installed but still don't get the output :(
Omkar77
Is it necessary to install VSC in disk c ?
Omkar77
And extensions also ?
Duncan
Installed but still don't get the output :(
I learned how to use VSC and use C++in youtube
Omkar77
Yeah I also tried same
Duncan
Can u tell me this ?
Honestly I'm not sure coz I'm not using windows
Omkar77
Ohk
ɴꙩᴍᴀᴅ
Lol? I just tried to link the vs code steps from the Rose message 🤪
😀😀
/notes
Nuri
/notes
Wojak
#findprojects
Omkar77
#cpp-vscode
Yes I installed thanks 👍
ɴꙩᴍᴀᴅ
Hasan Emre
I have 10 element linked list: Root-10-20-30-40-50-60-70-80-90-100-Null I managed to divide this in half: Root-10-20-30-40-50-Null Ptr2-60-70-80-90-100-Null How can I do this titled list like this: 60-70-80-90-100-10-20-30-40-50-Null
محمود
Write a program to subtract two numbers using function
Hasan Emre
Not happening
Harsh
Write a program to subtract two numbers using function
U need to learn "functions, function arguments and return statement". That's all
Mahsun
#offtopic
Anonymous
Hey I am from india
Anonymous
Hey I am from india
Hey, we don't need this information
Anonymous
Yeah ok bro
Anonymous
Anyone can tell me how to configure andro rat
Sandro
Anonymous
Bro I new in telegram also dry for inconvenience
Anonymous
I didn't read rule sry
Pavel
Is there a potential case when this function can return not 1 for valid a and b (not inf, not NaN or sNaN)? int compare(float a, float b) { int n = 0; n += (a == b); n += (a > b); n += (a < b); return n; }
Pavel
I think I've become too paranoid lately
Hasan Emre
@Sandroid75 Come to private chat?
Pavel
Why you mix float arguments with integers numbers?
I implicitly cast bool results of comparisons to int here (just to make the example shorter)
VAIBHAV
Hey guys I'm facing some kinda problem in file handling (using C) Question : WAP to copy data from a file into different file . My program successfully copy it but problem is compiler GCC return infinite run if I use copy variable type as integer And phone compiler ( it's written Clang 6.0.0 ) return infinite run if I use copy variable type as character And I'm confused 😔
Anonymous
Show the code
VAIBHAV
Show the code
Should I paste it or send .c file
Anonymous
You should paste via paste.ubuntu.com
VAIBHAV
You should paste via paste.ubuntu.com
https://paste.ubuntu.com/p/bHPkrnWBkZ/
Anonymous
Hi In c or c++ sometimes in the scence of work gwith strings we come across with things like this: "%d" or "%s" I wanna know that what's this mean?
Igor🇺🇦
https://paste.ubuntu.com/p/bHPkrnWBkZ/
It seems that you're not initialising int copy; before you use it in while(copy != EOF) { fputc(copy, new); copy = fgetc(source); } did you try while ((copy = fgetc(source)) != EOF) { fputc(copy, new); } ? This is undefined behaviour as it's written now.
Anonymous
https://www.knowprogram.com/c-programming/printf-in-c/
Before Reading I see that in this article this matter is attributed to printf. Is same for cout or not? Or all of that is explained in article?
Igor🇺🇦
Before Reading I see that in this article this matter is attributed to printf. Is same for cout or not? Or all of that is explained in article?
No, cout doesn't use formatter like this. We don't need them in C++ because of operator overloading
AHMED
I want book recommendations for learning c++ for beginners. THANKS
....
im a newbie and i got this error plz anyone can help me?
....
.exe has stopped working code blocks
olli
.exe has stopped working code blocks
your programs produce an access violation