Created
May 19, 2011 23:59
-
-
Save nus/982060 to your computer and use it in GitHub Desktop.
Sleep sort
This file contains hidden or 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 <boost/lexical_cast.hpp> | |
#include <boost/date_time/posix_time/posix_time.hpp> | |
#include <boost/bind.hpp> | |
#include <boost/thread.hpp> | |
using namespace std; | |
using namespace boost; | |
/* | |
Sleep sort (http://dis.4chan.org/read/prog/1295544154) | |
$ ./slee_sort 8 2 4 5 | |
2 | |
4 | |
5 | |
8 | |
only positive number | |
*/ | |
void sleep_and_print(double ms) | |
{ | |
this_thread::sleep(posix_time::milliseconds(ms)); | |
cout << ms << endl; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
thread_group t; | |
for(int i = 1; i < argc; i++) { | |
double ms; | |
try { | |
ms = lexical_cast<double>(argv[i]); | |
} | |
catch(...) { | |
continue; | |
} | |
t.create_thread(bind(sleep_and_print, ms)); | |
} | |
t.join_all(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment