• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

LICENSES/H03-May-2022-

autotests/H03-May-2022-2,7022,058

benchmarks/H03-May-2022-293231

docs/H04-Dec-2021-158139

examples/H03-May-2022-2,5751,995

src/H03-May-2022-6,0593,702

.git-blame-ignore-revsH A D04-Dec-2021149 65

.gitignoreH A D04-Dec-2021305 2928

.gitlab-ci.ymlH A D04-Dec-2021373 86

.kde-ci.ymlH A D04-Dec-2021131 86

KF5ThreadWeaverConfig.cmake.inH A D04-Dec-2021194 95

README.mdH A D04-Dec-20212.9 KiB7148

internal-doxygen.cfgH A D04-Dec-202148.8 KiB1,213860

metainfo.yamlH A D04-Dec-2021393 2220

README.md

1# ThreadWeaver
2
3Helper for multithreaded programming
4
5## Introduction
6
7ThreadWeaver is a helper for multithreaded programming.  It uses a job-based
8interface to queue tasks and execute them in an efficient way.
9
10You simply divide the workload into jobs, state the dependencies between the jobs
11and ThreadWeaver will work out the most efficient way of dividing the work between
12threads within a set of resource limits.
13
14See the information on [use cases](@ref usecases) and
15[why multithreading can help](@ref multithreading), as well as the usage
16section below, for more detailed information.
17
18
19
20## Usage
21
22If you are using CMake, you need to have
23
24    find_package(KF5ThreadWeaver NO_MODULE)
25
26(or similar) in your CMakeLists.txt file, and you need to link to
27KF5::ThreadWeaver.
28
29ThreadWeaver is a Job queue. It executes jobs in threads it internally manages.
30The minimum and maximum number of threads provided by a Weaver is set by the
31user. Jobs are regular QObjects, which allows users to connect to the `done()`
32signal to be notified when the Job has been executed. The Weaver class provides
33objects that handle a number of threads called the inventory. Users usually
34acquire a reference to a WeaverInterface object.
35
36Jobs may depend on other jobs. A job will only execute if all jobs it depends
37on are already finished. In this, dependencies reorder job execution.  If no
38dependencies are declared, jobs are executed in queueing order. Multiple
39dependencies are possible, which allows the creation of complex flow graphs
40that are automatically executed by the Weaver. It is important, though, to
41avoid circular dependencies. Two jobs that depend on each other in both
42directions will simply never be executed, since the dependencies will never
43resolve.
44
45Threads are created on demand and do not exit until the containing weaver is
46deleted. Threads have an eager policy in trying to execute jobs out of the
47queue. The managing Weaver blocks them if no jobs are available.
48
49WeaverObservers are used to receive more informative events about the thread
50states and job execution. They can be used to provide progress or debugging
51information or to implement GUIs to show the thread activity. Observers can be
52attached to Weavers and will disconnect automatically when they are deleted.
53
54### Job Execution
55
56In general, jobs are executed in the order they are queued, if they have no
57unresolved dependencies. This behaviour can be used to balance I/O, network and
58CPU load. The SMIV example shows how this can be done.
59
60### Emitting Signals from Jobs
61
62To notify the application's GUI of progress or other events, it may be
63desirable to emit signals from the Job objects that can be connected to the
64main thread. Since the job will be executed in another thread, such signals are
65delivered asynchronously.
66
67The Job class in the ThreadWeaver library itself contains such a helper class
68that can be used as a reference for this approach.
69
70
71