You can't lock the mutex in a thread and unlock it in another one. I think you should read more about mutexes, you don't seem to understand how they work
To give you an answer, a correct version would look like this:
void thread();
{
while(1)
{
mutex.lock();
provide_data();
mutex.unlock();
}
}
void main();
{
thread.launch();
while(1)
{
mutex.lock();
use_data();
mutex.unlock();
}
}
But then your threads will never run in parallel, because when one is busy the other will always be waiting. You'll have to use the mutex more locally.
We won't be able to help you more unless you show more code.