I've got a sort of spell checker written in Delphi. It analyzes the text sentence by sentence. It encolors wrong items according to some rules after parsing each sentence. The user is able to interrupt this process, which is important. How can I parallelize this process in general using some 3rd party Delphi libraries? In the current state I've got on the fly sentence coloration after check. Thus the user sees the progress.
相关问题
- Is there a Delphi 5 component that can handle .png
- Is there a way to install Delphi 2010 on Windows 2
- Is TWebBrowser dependant on IE version?
- multidplyr : assign functions to cluster
- iOS objective-c object: When to use release and wh
相关文章
- How to use doMC under Windows or alternative paral
- Parallel while loop in R
- Does gfortran take advantage of DO CONCURRENT?
- Best way to implement MVVM bindings (View <-> V
- Windows EventLog: How fast are operations with it?
- Using Parallel Linq Extensions to union two sequen
- MPI and D: Linker Options
- How to force Delphi compiler to display all hints
The algorithm would be as such:
How the multiple spell-checkers will access the dictionary is another problem. You can load a copy of the dictionary in each worker or you can protect access to the dictionary with a lock (but that would slow things down). If you are lucky, dictionary is thread-safe for reading and you can do simultaneous queries without locking.
Appropriate OmniThreadLibrary abstraction for the problem would be either a ParallelTask or a BackgroundWorker.
To parallelize, just create a new class descendent from TThread, create an object from it, give part of the job to the new thread, run Execute, and collect the results in the main thread.
Like this:
In the main thread:
The thread object will then do the analyzing in the background, while the main thread continues to run.
To handle the results, you need to assign a handler to the OnTerminate event of the thread object:
This must be done before you run Execute on the thread object.
To allow for interruptions, one possibility is to break the main text up into segments, place the segments in a list in the main thread, and then analyze the segments one by one using the thread object. You can then allow for interruptions between each run.