I am writing a multithreaded desktop application.
Generally
I am unsure about the implications that multitreading has on the architecture. There is a lot of literature on architecture, but I know none that takes multithreading into account. There is a lot of literature on the low level stuff of multithreading (mutexes, semaphores, etc.) but I know none that describes how these concepts are embedded into an architecture.
Which literature do you recommend to fill this gap?
Particularly
My application consist of
Presentation
that creates and manages dialogs using a GUI toolkit,Kernel
that knows all about the domain of the application,Controller
that knows theKernel
and thePresentation
and moderates between these two.
To be more precise, here is how files are opened:
- The
Presentation
signals aFileOpenCommand
. - The
ApplicationController
recieves this signal and- uses the
ApplicationKernel
to create aFile
object, - uses the
ApplicationPresentation
to create aFilePresentation
object, - creates a
FileController
object, passing theFile
and theFilePresentation
to the constructor.
- uses the
- The
FileController
registers itself as an observer on itsFile
andFilePresentation
.
Let's say File
provides a long running operation Init()
that should not block the user interface. There are two approaches that came to my mind:
File::Init()
returns an object that encapsulates a thread and can be used to register an observer that is notified about progress, errors, completion etc. This puts a lot of responsibility into theFileController
(who would be the observer), because it is now accessed from both the main thread as well as from the working thread.- Hide the working thread completely from the
Controller
.File::Init()
would return nothing, but theApplicationKernel
would signal creation, progress and errors of long running operations in the main thread. This would drag a lot of communication though theApplicationKernel
, turning it into something like a god object.
Which of these two is the common approach to multithreading in a desktop application (if any)? Which alternative approaches do you recommend?