You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+51-36
Original file line number
Diff line number
Diff line change
@@ -7,70 +7,85 @@ C shim for [task copying](https://github.com/JuliaLang/julia/issues/4085) in Tur
7
7
8
8
## Getting Started
9
9
10
+
Stack allocated objects are deep copied:
11
+
10
12
```julia
11
13
using Libtask
12
14
13
-
# Stack allocated objects are deep copied.
14
-
functionf_ct()
15
-
t =0;
15
+
functionf()
16
+
t =0
16
17
whiletrue
17
18
produce(t)
18
19
t =1+ t
19
20
end
20
21
end
21
22
22
-
t =CTask(f_ct)
23
+
ctask =CTask(f)
24
+
25
+
@showconsume(ctask) # 0
26
+
@showconsume(ctask) # 1
27
+
28
+
a =copy(ctask)
29
+
@showconsume(a) # 2
30
+
@showconsume(a) # 3
31
+
32
+
@showconsume(ctask) # 2
33
+
@showconsume(ctask) # 3
34
+
```
23
35
24
-
consume(t) ==0
25
-
consume(t) ==1
26
-
a =copy(t);
27
-
consume(a) ==2
28
-
consume(a) ==3
29
-
consume(t) ==2
30
-
consume(t) ==3
36
+
Heap allocated objects are shallow copied:
31
37
32
-
# Heap allocated objects are shallow copied.
38
+
```julia
39
+
using Libtask
33
40
34
-
functionf_ct2()
35
-
t = [012];
41
+
functionf()
42
+
t = [012]
36
43
whiletrue
37
44
produce(t[1])
38
45
t[1] =1+ t[1]
39
46
end
40
47
end
41
48
42
-
t=CTask(f_ct2)
49
+
ctask=CTask(f)
43
50
44
-
consume(t) ==0
45
-
consume(t) ==1
46
-
a =copy(t);
47
-
consume(a) ==2
48
-
consume(a) ==3
49
-
consume(t) ==4
50
-
consume(t) ==5
51
+
@showconsume(ctask) # 0
52
+
@showconsume(ctask) # 1
51
53
52
-
# `TArray` implements a copy-on-write array. This is useful for task copying.
53
-
# In constrast to standard arrays, which are only shallow copied during task copying,
54
-
# `TArray` are deep copied after task copying.
54
+
a =copy(t)
55
+
@showconsume(a) # 2
56
+
@showconsume(a) # 3
55
57
56
-
functionf_cta()
57
-
t =TArray(Int, 1);
58
-
t[1] =0;
58
+
@showconsume(ctask) # 4
59
+
@showconsume(ctask) # 5
60
+
```
61
+
62
+
`TArray` implements a copy-on-write array. This is useful for task copying.
63
+
In constrast to standard arrays, which are only shallow copied during task copying,
64
+
`TArray` are deep copied after task copying:
65
+
66
+
```julia
67
+
using Libtask
68
+
69
+
functionf()
70
+
t =TArray(Int, 1)
71
+
t[1] =0
59
72
whiletrue
60
73
produce(t[1])
61
74
t[1] =1+ t[1]
62
75
end
63
76
end
64
77
65
-
t =CTask(f_cta)
78
+
ctask =CTask(f)
79
+
80
+
@showconsume(ctask) # 0
81
+
@showconsume(ctask) # 1
82
+
83
+
a =copy(ctask)
84
+
@showconsume(a) # 2
85
+
@showconsume(a) # 3
66
86
67
-
consume(t) ==0
68
-
consume(t) ==1
69
-
a =copy(t);
70
-
consume(a) ==2
71
-
consume(a) ==3
72
-
consume(t) ==2
73
-
consume(t) ==3
87
+
@showconsume(ctask) # 2
88
+
@showconsume(ctask) # 3
74
89
```
75
90
76
91
Note: The [Turing](https://github.com/TuringLang/Turing.jl) probabilistic programming language uses this task copying feature in an efficient implementation of the [particle filtering](https://en.wikipedia.org/wiki/Particle_filter) sampling algorithm for arbitary order [Markov processes](https://en.wikipedia.org/wiki/Markov_model#Hidden_Markov_model).
0 commit comments