Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <thread>
- #include <unistd.h>
- typedef struct Alarm
- {
- std::string message;
- int delay;
- }Alarm;
- class Client
- {
- private:
- int x;
- int y;
- int z;
- std::vector<std::thread> threads;
- std::vector<Alarm> alarms;
- public:
- Client()
- {
- }
- ~Client()
- {
- }
- void printAlarm(std::string alarmString, int delay)
- {
- while(1)
- {
- std::cout << alarmString << std::endl;
- std::this_thread::sleep_for (std::chrono::seconds(delay));
- }
- }
- void setAlarm(std::string alarmString, int delay)
- {
- std::cout << "Thread: " << alarmString << std::endl;
- std::thread alarm(&Client::printAlarm, this, alarmString, delay);
- threads.push_back(std::move(alarm));
- }
- };
- int main()
- {
- Client cl;
- cl.setAlarm("GO AWAY", 1);
- std::cout << "It doesn't work" << std::endl;
- cl.setAlarm("AWAY GO", 3);
- int z;
- std::cin >> z;
- cl.setAlarm("DZIALA", 1);
- while(1);
- return 0;
- }
Add Comment
Please, Sign In to add comment