Created
January 21, 2013 23:18
-
-
Save bgunton/4590476 to your computer and use it in GitHub Desktop.
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
# Compile with "g++ -pthread -std=gnu++0x test.cpp" | |
#include <thread> | |
#include <iostream> | |
#include <vector> | |
class Socketor | |
{ | |
public: | |
std::vector<std::thread> threads; | |
static void processMessages(Socketor* s) { | |
std::string msg = "Hello"; | |
while(true) { | |
s->processMessage(msg); | |
} | |
} | |
virtual void processMessage(std::string) = 0; | |
Socketor() {} | |
~Socketor() { for(auto &i : threads) i.join(); } | |
}; | |
class Logger : public Socketor | |
{ | |
public: | |
void processMessage(std::string msg) { | |
std::cout << "Message: " << msg << std::endl; | |
} | |
void start() { | |
threads.push_back(std::thread(processMessages, this)); | |
} | |
}; | |
int main(int argc, const char** argv) | |
{ | |
Logger l; | |
l.start(); | |
return(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment