Pavel
Anybody with knowledge about multithreading in c++
There are many such programmers here, why not just ask your question right away
Anonymous
There are many such programmers here, why not just ask your question right away
If I create a 3 threads all with block of codes to execute, how does it work internally As in how does the CPU and other stuffs handle it, Second have you worked with multithreading before, why did you use it
Misagh
If I create a 3 threads all with block of codes to execute, how does it work internally As in how does the CPU and other stuffs handle it, Second have you worked with multithreading before, why did you use it
Threads are handled by the operating system. A program is ran through its process which consists of some threads. The threads share the executable code and other stuff from the process. The CPU executes individual instructions. each core does 1 instruction at a time. Now the operating system (the scheduler) does context-switching to constantly switch between the threads making it look like they are running in parallel which may not really be the case (unless they are ran through different cores)
Misagh
Found a code on c++ and threads were passed blocks of codes, now in big systems do they really pass just functions to std::threads?
I haven't done much multi-threading but well, what else is there to do except giving the thread a function to execute? and some parameters besides it. The executed function can do a lot and interact with the process' environment not necessary in its own thread. This is where thread synchronization and thread safety comes to play.
Sarthak
Hello my name is Sarthak I want to learn the basic and C programing in details from starting... Can anyone please help me 🙏
Pavel
Found a code on c++ and threads were passed blocks of codes, now in big systems do they really pass just functions to std::threads?
Usually yes, you pass a function which will be executed in that thread (in my case these function contain while(true) loop where the thread basically waits for the data that it needs to process and processes this data)
Pavel
🤔 I see
I can't find simple examples from my code, but here https://github.com/gameraccoon/hide-and-seek/blob/develop/src/GameLogic/Render/RenderThreadManager.cpp You can see that RenderThreadManager::RenderThreadFunction is just waiting for the data or a command to shutdown, when it gets one of these it continues execution and does something Also note startThread and shutdownThread functions
Sarthak
Thank you it is very useful 🤩
Pavel
So in short multithreaded apps like web browsers can't let you browse and download stuffs at the same time if such tasks did not have their own individual threads
Well, even if you have everything in one thread you can split a task into chunks and execute chunks of work from multiple tasks one after another so for the user there will be an illusion of multitasking. There are also different approaches like coroutines and fibers. Things like downloading a file are really better to be done in a separate thread because it's usually a long operation that would otherwise freeze UI of the user.
M
Hi guys
M
I got this error: error: implicit declaration of function 'srand' is invalid in C99
M
How can I update VS code to use the most recent standard to compile? (I have MacOS)
\Device\NUL
srand() function is from stdlib.h header
♾️
Hello
Laopigo
yeah i can use that but i need to use typedef
typedef struct object { // ... struct object *object_ptr; } object; Or typedef struct object object; // ... struct object { // ... object *object_ptr; };
Kevin
There is a task I am working on and there is a part that am unable to execute. Is there someone perfect on c++ that can guide me through please, even if it's paying i can
M
#include <stdlib.h>
thanks I figured it out
Naol D
Thanks !
i was using a void pointer but this one is better !
smene
Hi guys, may anyone help me to build https://github.com/libcpr/cpr for Visual Studio 17 (2022)?
Anonymous
include<stdio.h> int dost(int a, int b, int c); int main() { dost(); return 0; } int dost(int a, int b, int c) { printf ("Enter first number\n"); scanf("%d", &a); printf ("Enter second number\n"); scanf("%d", &b); c = a + b; printf("The sum is : %d", c); return a + b; }
Anonymous
What is wrong in this code ?
Anonymous
Its giving error
Евгений
Wait
Евгений
Made a mistake
Anonymous
Евгений
Not did compile
I know, i made a mistake typing it))
Anonymous
Yeah
Евгений
Try just return c;
Anonymous
Евгений
Changed returned type to void, and no need to return a+b;
Dima
yep but what is the point then
Anonymous
Евгений
include<stdio.h> int dost(int a, int b, int c); int main() { dost(); return 0; } void dost(int a, int b, int c) { printf ("Enter first number\n"); scanf("%d", &a); printf ("Enter second number\n"); scanf("%d", &b); c = a + b; printf("The sum is : %d", c); }
Евгений
Above also change to void. Not int.
Anonymous
But i want in return
Евгений
In your code it looks like you don't need to use a return statement
Евгений
Wait a moment, minutes. I cant use phone
Евгений
I'll help you))
Anonymous
Sure
Gilded
which is best compiler for c++ in windows please say
Евгений
Sure
#include <stdio.h> int dost(); int main() { dost(); return 0; } int dost() { int a, b; printf("Enter a number: "); scanf("%d", &a); printf("Enter a number: "); scanf("%d", &b); return printf("%d + %d = %d", a, b, (a + b)); }
Евгений
Hope I helped you:)
Евгений
Sure
#include <iostream> int getNumber(int value) { std::cout << "Enter a number: "; std::cin >> value; return value; } void showResult(int a, int b) { std::cout << a << " + " << b << " = " << (a + b) << '\n'; } int main() { int a{}, b{}; a = {getNumber(a)}; b = {getNumber(b)}; showResult(a, b); }
Евгений
Or maybe like this, if you like))
Kevin
Wait a moment, minutes. I cant use phone
Hello ,I have inboxed you, was wondering if you can give me direction about my code, maybe you can go through it and see if am right? Just need help from an expert
Kevin
Thanks
Евгений
Sure
Bro, even better for you. Just for learning)) #include <iostream> int getNumber() { int value; std::cout << "Enter a number: "; std::cin >> value; return value; } void showResult(int a, int b) { std::cout << "Result: " << a << " + " << b << " = " << (a + b) << '\n'; } int main() { showResult(getNumber(), getNumber()); }
Евгений
Visual studio or CLion
Gilded
Visual studio or CLion
visual studio how to correct indent of code
Ludovic 'Archivist'
which is best compiler for c++ in windows please say
Probably Microsoft Visual C++ Compiler
Евгений
yes
Google it. It's very easy))
Ludovic 'Archivist'
visual studio how to correct indent of code
I think it is Shift+F6 but not sure
Евгений
In CLion is Crtl+Alt+L
Gilded
I think it is Shift+F6 but not sure
its shift+alt+f in google shows error "there is no formatter for cpp installed" i installed around 10+ extensions just for it no change
Ludovic 'Archivist'
Ah then yeah, no formater, The only supported one is Clang-Format iirc
Евгений
yes
Bro, I know, just put a semicolon (;) at the end of the last bracket which is "}" after return statement. It'll indent the whole code inside one . CPP file:)
Gilded
i used xcode in mac till now, but now shifted to new windows laptop i was comfortable with xcode
Евгений
Gilded
Is it work with a semicolon at the end of the last } ???
i have to save,close and open for that?