Created
November 24, 2015 17:45
-
-
Save lucarin91/f5363324ed907b27716f to your computer and use it in GitHub Desktop.
spawn a thread that print a loading spin on the terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <thread> | |
#include <unistd.h> | |
using namespace std; | |
int main(int argc, char* argv[]){ | |
thread([](){ | |
for(char symbol = 0;;usleep(100000)){ | |
cout << "\r" << (0==++symbol%4?"|": | |
1==symbol%4?"/": | |
2==symbol%4?"-": | |
"\\") << flush; | |
} | |
}).detach(); | |
// DO SOMETHINGS | |
for(;;){} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
compile on linux with pthread librery, like:
g++ -std=c++11 -pthread text_spin.cpp -o text_spin