multi threaded Persistent mapping

Hi,
I have written an app that uses the persistent mapping technique.
I use 2 different threads on the app - upload thread and drawing thread.
The upload thread uploads the data to the mapped buffer using the std:copy command, while the drawing thread displays the data using the openGL commands.
when I try to upload a big amount of data that is changing fast (e.g. ~5000 triangle every 5 milliseconds), the display shows sometime garbage.

I tried to perform the same code synchronously, e.g upload and draw on the same thread, and everything looks good.
I used debug printings and it seems that the same offsets and data I upload on one thread is what I read and display on the other thread.

The mapping is like this:

glBindBuffer(m_bufferDataType, m_glBufferId);
const GLbitfield flags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT;
glBufferStorage(m_bufferDataType, m_bufferSize, NULL, flags);
m_glBufferDataPtr = (char*)glMapBufferRange(m_bufferDataType, 0, m_bufferSize, flags);
glBindBuffer(m_bufferDataType, 0);

The upload looks like that:

std::copy(_data.begin(), _data.end(), (T*)(m_glBufferDataPtr + m_uploadOffset));

I use fences to sync the buffer for not uploading data the a section while it is in use of the GPU.

Does anyone have an idea why it is happening?
Thanks.

Ok… I found the problem, I had a problem on my code.
Now everything works great.

So what was the problem? I think you have a number of us curious.

I have put the glfence before the draw call by mistake, and it caused the fence to be released right after the draw,
and when the upload occurd the range seemed to be released even though the GPU still used it.

Ah! That makes sense. Thanks!