comparison doc/os.rst @ 322:44f336460c2a

Half of use of burg spec for arm
author Windel Bouwman
date Mon, 27 Jan 2014 19:58:07 +0100
parents doc/design.rst@ea93e0a7a31e
children 9eb1fc6aad6c
comparison
equal deleted inserted replaced
321:8c569fbe60e4 322:44f336460c2a
1 OS
2 ==
3
4 Design
5 ------
6
7 Processes / threads
8 ~~~~~~~~~~~~~~~~~~~
9
10 Processes are completely seperated and fully pre-emptive.
11 This means a process can be unscheduled at any moment.
12
13 Threads are co-operative. This means they yield control
14 voluntary. This means that mutexes and locks are not required.
15 This is done with the built-in language feature called tasks.
16
17 If some heavy duty task must be performed, either way spawn
18 a new process, or yield frequently from this hard labour.
19
20 tasks
21 ~~~~~
22
23 Consider the following:
24
25 .. code::
26
27 function int insanemath(int a)
28 {
29 while (a > 0)
30 {
31 a = a -1;
32 resume agent1;
33 }
34 return a - 1;
35 }
36
37 task agent1()
38 {
39 start agent2;
40 }
41
42 task agent2()
43 {
44 insanemath(55);
45 insanemath(44);
46 }
47
48 task main()
49 {
50 start agent1;
51 join agent1;
52 }
53
54
55 Say to tasks are running in concurrent / parallel.
56
57
58
59 Stack layout for tasks.
60 ||
61 ||
62 \/
63 +---------+
64 | return address
65 | locals
66 |
67 +------
68 | return address
69 | locals
70 |
71 +---
72
73 Assembly code for the functions above:
74
75 .. code::
76
77 .code
78 insanemath:
79 L1:
80 load r0, sp - 4
81 cmp r0, 0
82 jl L2
83 dec r0
84 store r0, sp - 4
85 jmp L1
86 L2:
87 ret
88
89 agent1:
90 hlt?
91
92 agent2:
93 hlt?
94
95 main:
96 jmp agent1
97
98 .data
99 agent1_task:
100 dd 0
101 agent2_task:
102 dd 0
103