Help me understand this. Here is the context.
- I am writing a program in C++.
- I have 2 buffers (deque). Let's call them buffer1 and buffer2;
- I have 2 threads: one thread is filling buffer1 with random values. The other one is copying the oldest buffer1 value to buffer2;
- I am using mutexes.
I want to copy the value inside the 1st position of buffer1 to the buffer2 and, in order to perform to do this, I write the following code line:
THREAD 1
double a = 20.1;
buffer1.push_back(a);
THREAD 2
buffer2.push_back(buffer1.front());
My question is: performing this, am I copying the value or passing the value by reference? I explain my question. I am having a random memory problem while running the program. I want to be sure if the source of the problem is here.
Thank you, everyone.