|
From: Jeroen <jv...@gm...> - 2016-04-15 19:19:16
|
On Fri, 15 Apr 2016 20:22:19 +0200 Martin Preuss <ma...@aq...> wrote: >Hi, > >I'm using FOX 1.6. > >If I remember correctly, FOX functions must only be called from within >the main thread. However, I want a worker thread to prepare some data >which needs then to be displayed as soon as it's ready (and convenient >for the main thread). > >Can someone please hint me as to how data can safely be transported >from a side thread to the main thread? There is a way for a worker thread to invoke functions in the main GUI thread: In FOX 1.6: FXGUISignal. In FOX 1.7: FXMessageChannel. In both cases, the idea is to pass some data from the worker thread to the main GUI (application) thread. You can also use common synchronization objects like Event or Semaphore, or pipes or some other waitable object (a synchronization primitive that can be waited on my MsgWaitForMultipleObjects() or select(). These are actually the underlying the FXMessageChannel. FXApp's addInput() is used to add a handle to the list of "watched" handles. This means, whenever main GUI thread returns to FXApp and blocks for events, it'll now also watch this other handle (in addition to the source of user- events). When the handle becomes raised, the main thread invokes SEL_IO_READ callback and then performs some action on behalf of the worker thread. Of course shared data structures must be accessed with some guards against concurrent modification; typically, mutexes or semaphores. To make life easy, FXApp provides a mutex covering everything a GUI thread may touch:- this mutex is only released when GUI thread blocks in select() or MsgWaitForMultipleObjects(). [This may be a bit course but its quite effective, since GUI threads tend to be blocking 99% of the time, it will actually work quite well in practice]. Hope this helps, -- JVZ -- +----------------------------------------------------------------------------+ | Copyright (C) 14:00 04/15/2016 Jeroen van der Zijp. All Rights Reserved. | +----------------------------------------------------------------------------+ |