Re: [twsocket] Interesting multithreading issue: race condition when triggering an event handler

2006-08-07 Thread Francois Piette
> > This raise the following question : Is a field variable in a class > > aligned in memory ? (OnMyEvent variable is just a field variable). > > I don't know, and it also raises a second question: > > Reads and writes to variables of > > other sizes are not guaranteed to be atomic on any platform

Re: [twsocket] Interesting multithreading issue: race condition when triggering an event handler

2006-08-06 Thread Wilfried Mestdagh
Hello Francois, > Line3: if Assigned(OnMyEvent) then > Line4: OnMyEvent(Self, MyArg); Very interesting issue. Because almost all components are coded like this. Very interesting solution also, clean and simple :) --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamic

Re: [twsocket] Interesting multithreading issue: race condition when triggering an event handler

2006-08-06 Thread Francois PIETTE
> procedure TMyComponent.TriggerMyEvent(MyArg : Integer); > begin >EnterCriticalSection(SomeSection); >if Assigned(OnMyEvent) then >OnMyEvent(Self, MyArg); >LeaveCriticalSection(SomeSection); > end; > > Now we're certain that nothing would change OnMyEvent between the > "if...th

Re: [twsocket] Interesting multithreading issue: race condition when triggering an event handler

2006-08-06 Thread Piotr Dałek
Hello! >>> I've found an interesting multithreading issue which is related not only >>> to >>> ICS component but many many other components I've seen so far. It is a >>> race >>> condition between two thread where one is triggering an event handler and >>> the other is removing (setting to nil)

Re: [twsocket] Interesting multithreading issue: race condition when triggering an event handler

2006-08-06 Thread Francois PIETTE
>> I've found an interesting multithreading issue which is related not only >> to >> ICS component but many many other components I've seen so far. It is a >> race >> condition between two thread where one is triggering an event handler and >> the other is removing (setting to nil) the event hand

Re: [twsocket] Interesting multithreading issue: race condition when triggering an event handler

2006-08-06 Thread Piotr Dałek
Hello! > I've found an interesting multithreading issue which is related not only to > ICS component but many many other components I've seen so far. It is a race > condition between two thread where one is triggering an event handler and > the other is removing (setting to nil) the event handl