Re: QtConcurent and QCache
You can wrap your cache in a class that will provide appropriate synchronization using i.e. QReadWriteLock. It will slow down processing a bit but you won't wreck your cache.
Re: QtConcurent and QCache
I actually have a locker at my getObject but it did not help. My problem is that when i created MyObject it will be attached to the current thread, and some other thread was given by it when its available on my cache. I don't think there is racing issue, i think its just the limitation of having a cache.
I have another problem to deal with when cache deletes the objects to make room and maybe the object is used by other thread. i think i will deal with this later .. or should i .. or maybe they are of the same nature..
thanks for the inpit wysota.. keep it coming.
baray98
Code:
MyObject* DataSource::getObject(int index)
{
//check if its in cache
MyObject* o = isInCache(index);
if (o) return o;
//if not
o = new MyObject();
addToCache(index,o); //note : o will be created under whoever thread is calling so the next time i will give to other thread this will error out
return o;
}
Re: QtConcurent and QCache
Does MyObject inherit QObject?
Re: QtConcurent and QCache
yes .. is it bad?
baray98
Re: QtConcurent and QCache
Yes, it is. QObjects are not thread-safe, you can't use them from within different threads at once.
Re: QtConcurent and QCache
So if i pull this MyObject out of QObject should solve my threading problem .. interesting .. i should try it.
baray98