Hey guys,
I haven't used thread for a long time and would need some help.
I would like to have a endless loop:
1 2 3 4
|
Update()
{
while(true){...}
}
| |
I know there is std::thread but i think i don't use it correctly:
1 2 3
|
std::thread t1(Update);
t1.join -->??
| |
can anybody help me with this simple example :P?
Last edited on
join will wait for the thread to finish. If the thread is designed to never end, join is going to wait forever.
So under what circumstances do you actually want the thread to end?
ahm hmm.
the main problem is, that the loop currently consumes too much cpu, because its running for a certain amount of time, maybe even for ever.
Therefore i thought a thread would be a good idea.
But as already meantioned, the loop&thread would run for a certain amount of time or even forever
If it's meant to run forever anyway, why bother waiting for it? Just let it run while your main thread gets on with whatever else has to be done.
so this would be enough?
1 2 3 4 5 6
|
int main()
{
std::thread t1(Update);
.......
}
| |
or do i need a second one for other stuff? :P
Last edited on
The main function will carry on after creating the thread named t1. Do the other stuff in the main function.