The entry workers
The source src/modules/demonstrations/workers built with the setting DRAWING_THROUGH_MODULE=true. The text after this paragraph is the comment of that source.
A demonstration of the lock and of the word wait.
One process, five threads, one queue of work. The first thread cuts a picture in tiles and puts all the tiles in the queue. Four threads take the tiles: each tile is computed by the thread that took it, and has the tint of this thread. A lock keeps the queue correct. A thread with no work waits on a word of memory; the first thread changes the word and wakes the four threads.
Before the picture, the four threads add to one number, first with the lock, then with no lock. With no lock, additions are lost.
What it is for. It shows the two tools of the system for threads that share memory: the lock of the system library, which counts its waits, and the word wait of the kernel, where a thread sleeps on a word of memory with no kernel object. The sum with no lock shows why the lock exists.
Start: start("workers") in the console, or the bar of the desktop. Its row of start_grant_sets has no grant; its budget has room for 9 threads.
What a reader sees: the picture in the tints of the four threads, which zooms in at each new picture, the tiles of each thread and the waits of the lock. The log has:
- "workers: with the lock, 4 threads made N additions: the number is N, W waits";
- "workers: with no lock, ...: the number is M", where M is usually smaller than N;
- "workers: the lock lost no addition";
- "workers: ok, 4 threads computed T tiles: A B C D" after the first picture.
workers module with an entry
- Hash
18457a6ff646f83fb311bab2dd19b7510bfe19ed2366fa83ab82896ac7523c4c- Size
151523 bytes- Exports
0- Imports
1- Imported by
0- License
- MIT
A demonstration of the lock and of the word wait
| Fact | Value |
|---|---|
| Kind | Modules with an entry |
| Source | src/modules/demonstrations/workers |
| Boot image | yes: in the boot image, 151523 bytes in this build |
| Build settings |
|
| Imports | |
| Imported by | none |
Neighbours
What it imports, at its left, and what imports it, at its right: the part of the module graph that touches it.
Exports
| Export | What it does |
|---|---|
entry() | The entry of workers: the two sums, then the four workers, then a loop that gives them a new picture after each pause |
entry
entry()
The entry of workers: the two sums, then the four workers, then a loop that gives them a new picture after each pause.
With no window, or when a thread does not start, it stops with the code
- 1. The first thread never computes a tile: it fills the queue, changes the word that the workers wait on, and draws at the rate of the screen.
- Form
- The entry of the module: one parameter, an address, fixed by the contract.
src/modules/demonstrations/workers/main.odin:206
Read from the source of the module, as the build reads it to describe the exports (tools/modustool/build/describe.odin).
What the root service gives it
| What | Value | As the root service says |
|---|---|---|
| Grants | none | Five threads and one queue of work. |
| Other terms of its start grant set | none | |
| Budget that it asks for |
| The working memory: the rest of the pages that the root service gave it by its name, once the tool counts its module, its threads and its window: 1154 pages. And the glyph memory of the copy of the text rendering of the drawing module, which draws its text: 354 pages (display.TEXT_MEMORY_PAGES). 1154 + 354 = 1508. |
The start grant set is read from start_grant_sets in src/modules/system/root/start_grant_sets.odin. The stated budget is read from the constant MODULE_BUDGET of the source of the module (its line); the build adds the counted parts and writes the sum in the module (tools/modustool/build/budget_count.odin); the root service accepts it up to the largest budget of a process, and adds the limits of processor time and of log records (src/modules/system/root/budgets.odin).
start_grant_sets global variable of the package root
start_grant_sets := [?]Start_Grant_Set_Row {...}
The start grant set of each module of the boot image, with the reason of each.
