PDA

View Full Version : Accessing deleted memory, Producer Consumer app



^NyAw^
18th July 2008, 17:15
Hi,

I'm developing an application that contains 2 QThreads, one is the Producer and the other is the Consumer that have a ring buffer.

The ring buffer is an array of objects.

The Consumer does somethings on the object that is accessing and finally emits a signal with a pointer to that data to the Main Thread. The Main Thread takes the object(that is a pointer) and paints it's representation.

I'm emitting pointers instead of objects to speed up the application.

The problem is that when the Main Thread access to the data pointer, maybe it's being cleared(or filled) by the producer and then the application crash.

Is there any way to know if the memory pointer don't contains data?

I would like that Main Thread don't do anything if there is no real data.

Thanks,

Methedrine
19th July 2008, 13:26
You are using a mutex to ensure that there is no race condition between your thread?

^NyAw^
21st July 2008, 09:12
Hi,

Sorry for delay.



You are using a mutex to ensure that there is no race condition between your thread?


I'm using two QWaitConditions. The two threads work well without deadlocks. The problem is on visualization on the main thread where I don't want to use one more wait condition.

Thanks,

Methedrine
2nd August 2008, 13:58
Hi,

Sorry for delay.



I'm using two QWaitConditions. The two threads work well without deadlocks. The problem is on visualization on the main thread where I don't want to use one more wait condition.

Thanks,

Sorry for the delay with my reply, but the product my company is working is close to master date, so it's some sort of busy weeks at the moment.

Why not use another QWaitCondition? One way or the other you must tell your GUI Thread when it is allowed to fetch new data to render.