This is my code:
MessagesSender all;
std::thread t1(&MessagesSender::updateMessages,all);
std::thread t2(&MessagesSender::sendMessages,all);
all.signIn();
t1.join();
t2.join();
Inside the threads function there's a loop that keeps the thread running every sixty seconds. The sign in function changes one of the variables in 'all' but the threads ignore the change and don't update the object, as if I sent two different objects.
Here is my class:
class MessagesSender
{
public:
void Menu();
void signIn();
void signOut();
void showUsers();
bool checkIfExist(std::string name);
void updateMessages();
void sendMessages();
protected:
std::vector<std::string> users;
std::queue<std::string> messages;
};
And the signIn function:
void MessagesSender::signIn()
{
std::string name = "";
std::cout << "Enter name\n";
std::cin >> name;
if (checkIfExist(name))
{
std::cout << "User already exists!\n";
}
else
{
users.push_back(name);
}
}