std::mutex problems

I might be making a really simple mistake, but I have been searching around and not finding any answer that fixes my problem.

So I have a class that uses and needs static members and I want to make it thread safe as I am using it within other classes. I would like to use each of those other classes in different threads if needed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class mother {
private:
	static mutex mtx;
	static struct rsc {
		vector<dpair<size_t, string>> msg;
	} la;
	size_t m = 0;
public:
	void message( string mg ) {
		lock_guard<mutex> g(mtx);
		la.msg.resize(la.msg.size() + 1);
		m = la.msg.size() - 1;
		la.msg[m] = dpair<size_t, string>(m, mg);
	}
};

All seems fine to me, but when I use a class that inherits "mother". My program seems to run fine until it is time to exit. Then I get "this program is not responding". I know it has to do with the mutex because the second I take it out everything works as it should, no exit problems. What am I doing wrong here?
Last edited on
Topic archived. No new replies allowed.