Skip to content

Instantly share code, notes, and snippets.

@lucarin91
Created November 24, 2015 17:45
Show Gist options
  • Save lucarin91/f5363324ed907b27716f to your computer and use it in GitHub Desktop.
Save lucarin91/f5363324ed907b27716f to your computer and use it in GitHub Desktop.
spawn a thread that print a loading spin on the terminal
#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;
}
@lucarin91
Copy link
Author

compile on linux with pthread librery, like:
g++ -std=c++11 -pthread text_spin.cpp -o text_spin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment