Arno Garrels wrote: > Francois PIETTE wrote: >> I've found an interesting multithreading issue which is related not >> The solution is to rewrite the procedure as follow: >> >> Line1: procedure TMyComponent.TriggerMyEvent(MyArg : Integer); >> Line2: var >> Line3: TMyEventProc EventProc; >> Line4: begin >> Line5: EventProc := OnMyEvent; >> Line6: if Assigned(EventProc) then >> Line7: EventProc(Self, MyArg); >> Line8: end; >> Saving the event pointer in line5 make sure that it is still valid in >> the case a thread switch between Line 6 and 7 occur and the OnMyEvent >> is set to nil by the other thread. >> >> Interesting, isn't it ? > > I think it's better/faster than having critical sections for all > triggers, do you plan to change all ICS triggers accordingly?
This requires atomic reading/writing of a Pointer (no thread switch while read/write), I'm not sure whether this is true. Byte variables are written/read in one go, there's no ploblem. --- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be