Skip to content

Concurrency and Synchronization

As already stated in the parallel section, there is no keyword for the synchronization. The next statement after a parallel block is only started if all concurrently running tasks are finished.

The following example demonstrates the use of the parallel keyword and the implicit synchronization.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Struct Color
    name: string
    rgb: number[3]
End

Struct PaintingResult
    wetness: number
End

Struct SheetPart
    width: number
    length: number
End

Struct CuttingResult
    parts_count: number
    sheet_parts: SheetPart[]
End

Task productionTask
    # Execute paintingTask and cuttingTask in Parallel
    Parallel
        paintingTask
        cuttingTask

    # gets started when paintingTask and cuttingTask are finished
    paintingTask
End

Task paintingTask
    Painting
        In
            Color
                {
                    "name": "green",
                    "rgb": [0, 255, 0]
                }
        Out
            pr: PaintResult
End

Task cuttingTask
    Cutting
        Out
            cr: CuttingResult
End