The entry threads
The source src/modules/demonstrations/threads built with the setting DRAWING_THROUGH_MODULE=true. The text after this paragraph is the comment of that source.
A demonstration of threads. The design: Architecture: Threads.
One process, one address space, five threads. Each square is drawn by its own thread, in a picture that the threads share with the first thread: the threads share all the memory. The first thread shows the pictures in the window. The same procedure runs in the four threads; only the parameter record differs. The kernel gives the processor to each thread in turn: no thread calls another.
Each thread computes with floating point numbers. The kernel keeps the registers of each thread: a wrong picture means a lost register.
1 to 4: stop the thread of a square, or start it again
What it is for. It shows that a thread is cheap and that the kernel keeps its state whole: each square must stay correct while threads stop, start and share the processors. A thread that ends is a value that the first thread waits for: one thread first adds the numbers to 1000, and the first thread reads the sum in the shared memory.
Start: start("threads") in the console, or the bar of the desktop. Its row of start_grant_sets has no grant; its budget has room for 6 threads.
What a reader sees: four squares, each with its thread and its count of frames, or "stopped". The log has "threads: a thread added the numbers to 1000: 500500", then "threads: ok, 4 threads draw in one surface" when each square has a frame, and "threads: thread N stopped at frame F" or "started" after a key.
threads module with an entry
- Hash
1d7089e059d192fd81ebe0d95597f3b6710f6a8a15c50fd618a7c56ac3548d29- Size
147987 bytes- Exports
0- Imports
1- Imported by
0- License
- MIT
A demonstration of threads
| Fact | Value |
|---|---|
| Kind | Modules with an entry |
| Source | src/modules/demonstrations/threads |
| Boot image | yes: in the boot image, 147987 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 threads: one thread that ends, then four threads that draw, and a loop that shows their squares and stops or starts them on a key |
entry
entry()
The entry of threads: one thread that ends, then four threads that draw, and a loop that shows their squares and stops or starts them on a key.
With no window, or when a thread does not start, it stops with the code
- 1. The first thread never draws a pixel of a square: it only shows the pictures that the four threads wrote, at the rate of the screen. A key 1 to 4 ends the thread of that square (
thread_end), or starts a new one.
- Form
- The entry of the module: one parameter, an address, fixed by the contract.
src/modules/demonstrations/threads/main.odin:152
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 in one address space. |
| 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: 1389 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). 1389 + 354 = 1743. |
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.
thread_end procedure of the package system
thread_end :: proc "contextless" (thread: Thread)
thread_end stops a thread if it runs, then frees its stack and its handle.
