Sonjli 6 Posted October 29, 2019 Hi, I have this case where one OmniTask run some external code from a delphi library\Component that uses internally a TThread. This thread can't be accessed from outside. This external library have a class which listen for an incoming request and when this happens then it run a "onReceive" event. Something like a listening socket. One OmniTask "run" one and only one of these objects. Have I to pay attention when the "inside-thread" have to use write-resources of the Omnitask? For example when the "inside-thread" need to use the logger of the OmniTask? Some pseudo code: CreateTask( procedure(const task: IOmniTask) var lBroadcaster: IBroadcastManager; lLogger: ILogWriter; begin [...] task.Lock.Acquire; try lLogger.Log(TLogType.Info, 'Testing...', 'TEST'); finally task.Lock.release; end; [...] // lBroadcaster is the object using an internal tthread lBroadcaster.OnReceive := procedure(ABroadcastMessage: IBroadcastMessage) begin task.Lock.Acquire; try try lLogger.Log(TLogType.Info, 'Parsing...', 'TEST'); [...] except on E: Exception do begin lLogger.Log(TLogType.Error, 'Exception (%s): "%s"', [E.ClassName, E.Message], 'TEST'); end; end; finally task.Lock.release; end; end; lBroadcaster.Connect('127.0.0.1', 'guest', 'guest', True); ).SetParameter([...]) // All my stuff injiections .WithLock(CreateOmniCriticalSection) .Run; Is the locking mechanism used in the right way? Thanks Eddy Share this post Link to post
Primož Gabrijelčič 223 Posted October 30, 2019 It depends on how lBroadcaster's OnReceive callback is implemented. If that event is called in the context of the "inside thread", then yes - this locking is necessary and it is correctly implemented. 1 Share this post Link to post