Synchronisation problem

Oct 10, 2012 at 1:30 PM
Edited Oct 10, 2012 at 3:19 PM

Hi,

We are using your nice library for one of our project. And we think we found a little bug which occurs rarely.

TrackerAsync function "CallGenericLoad", try to call to "LoadToTracker" function, and can access at the same time to the data member "loadingAssetsStack" and so modify its count value.

We just add a "lock (loadingAssetsStack)" into the second while of function "LoadingThreadWorker" and a "lock (loadingAssetsStack)" before each call to "LoadToTracker". These calls permit to method to synchronise the async call with the sync call.

 

Regards

Oct 11, 2012 at 2:43 PM

Hi Tipoun,

I thought that I'd avoided the possibility that two assets could be loaded at once by using the "Queue<LoadAsyncParams>" and processing them one by one in a worker thread. On closer inspection though, the loop calls IsLoading which just returns "loadingAssetsStack.Count > 0". This must be where the race condition is occurring.

Thank you for finding this and reporting it too.

Cheers,

Aranda

Oct 11, 2012 at 2:50 PM

Indeed, our solution blocks parallels loading.

Have you another solution for this ? Or could you warn us when you correct it ?

Thank you for your help

Regards

Oct 11, 2012 at 3:25 PM

Are you calling a non-async Load<T> after kicking off some async load calls? I can see now this being a problem. ContentTracker was never designed to load multiple items in parallel, but instead it pushes all async loading to a worker thread and processes them sequentially. This will break down if Load<T> is called just after LoadAsync<T>.

Does your fix cause any noticeable problems for you? If not it may be perfectly fine.

To properly support async and non-async loading calls at once, ContentTracker would have to be changed so that "loadingAssetsStack" is not shared between the two. This is tricky as calls to LoadToTracker may come in from the main or the worker thread. Perhaps a dictionary mapping the thread id to a unique loadingAssetsStack would do the trick. 

Aranda

Oct 15, 2012 at 2:50 PM

>> To properly support async and non-async loading calls at once, ContentTracker would have to be changed so that "loadingAssetsStack" is not shared between the two.

We just try this. We test a little and warm you, if everything is okay.

 

Thank you for your help

Regards