Thread Synchronization Issue?

admin

Administrator
Staff member
This is my problem:

I've got a function listening to a particular event. When this function is invoked (the event has fired) it is supposed to do some work (a lot). However, this function is invoked a lot of times, as the event fires a lot. All events seem have their own threads, so several threads run the method concurrently. And this makes Explorer 5.0 hang.

So I'm wondering if there's some synchronization in explorer. I tried to solve it like this:


this.AFunction = function()
{
if(this.IsWorking)
{
return; //Or wait. I choose to ignore this event.
}

this.IsWorking = true;
//work your magic
this.IsWorking = false;
}


this should work: if an event is fired, the 'working' flag is set and all events fired will be ignored until the first event is done. In theory, that is.

In real life, the flag isn't always set to true even though 'this.IsWorking' has been set to true. How is this? I don't know how explorer handles threads, but I could imaging that they've done something stupid like duplicating primitives for each thread instead of letting them share them. Anyway, does anyone know how to fix this? Oh, and I have no control over the events.

Thanks on advance,
Nille
 
Back
Top