stopping threads without using local var?

hi, here's my code,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <unistd.h>
#include <thread>

using namespace std;

void Blink();

bool blinkit;
int main()
{
	blinkit = true;
	thread blink(Blink);
	sleep(5);
	blinkit = false;

	blink.join();
	return 0;
}

void Blink()
{
 	cout << "Hellow ";
	while(blinkit){
		cout << "0_0";
		cout << flush;
		sleep(1);
		cout << "\b\b\b";
		cout << "^_0";
		cout << flush;
		usleep(500000);
		cout << "\b\b\b";
	}
	cout << "\n Bye !" << endl;
}


the problem is i don't want to use local vars , is ther anyway do end the loop safely(removing all the vars used in function and ect) without using a local var ?
Last edited on
that's gonna help me a lot for other apps, thanks :) i love this forum :)

but is ther anyway to do it without a local variable? (only by creating a var inside the main or Blink function ! that is removed after the thread ends ! )

the links you gave me still require me to use local variables !
Last edited on
Your current code does not use a local variable. Do you mean "global" instead?

You could always pass the variable by reference to the thread.
Last edited on
Topic archived. No new replies allowed.