1

Simplified: I am writing plugins to realbasic. I have two plugins with their own threads. Everything is fine until i start to use std::vector. I have vector<> variables in both plugins and I am not using the vectors to use same data or to share data between threads or anything else. My model looks like this:

thread_1{ vector<> variable_1; foreach{ variable_1.push_back(something); } } thread_2{ vector<> variable_2; foreach{ variable_2.push_back(something); } } 

If I don't declare the vectors static, the program most of the times crashes. But even when i declare the variables static, and use some of algorithms like sort or copy, the crashes appear again. It seems like the operations on vector are using some abstract class which is not multithread safe or something. Or am I doing something wrong? Thank you.

I am using windows 7 x64, visual studio 2008 pro, compilation on release win32.

6
  • 5
    Perhaps the copy constructor for something is not thread safe? Commented Nov 21, 2011 at 10:07
  • 3
    Could you put the real code ? With what you posted, it is impossible to know if it comes from the multithreading situation or not. Commented Nov 21, 2011 at 10:07
  • I agree with the above comment about copy constructors. Reference counters that get modified asynchronously is a classical problem I believe. Commented Nov 21, 2011 at 10:09
  • You mentioned plugins, are they built by one project in a single binary? Or some kind of dlls? Commented Nov 21, 2011 at 10:38
  • SRY, the "something" is not the same class or type. I ment that variable_1 can be for example int and variable_2 of type double. Commented Nov 21, 2011 at 12:05

1 Answer 1

1

AFAIK, the allocator is not thread safe. You should either allocate vector (reserve) in a thread safe way or use a thread safe allocator.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.