@@ -28,6 +28,8 @@ find_in_node1_path(name) = myid()==1 ?
28
28
29
29
# Store list of files and their load time
30
30
package_list = (ByteString=> Float64)[]
31
+ # to synchronize multiple tasks trying to require something
32
+ package_locks = (ByteString=> Any)[]
31
33
require (fname:: String ) = require (bytestring (fname))
32
34
require (f:: String , fs:: String... ) = (require (f); for x in fs require (x); end )
33
35
@@ -38,7 +40,11 @@ function require(name::ByteString)
38
40
end
39
41
end
40
42
path = find_in_node1_path (name)
41
- has (package_list,path) || reload_path (path)
43
+ if has (package_list,path)
44
+ wait (package_locks[path])
45
+ else
46
+ reload_path (path)
47
+ end
42
48
end
43
49
44
50
function reload (name:: String )
95
101
96
102
function reload_path (path)
97
103
had = has (package_list, path)
104
+ if ! had
105
+ package_locks[path] = RemoteRef ()
106
+ end
98
107
package_list[path] = time ()
99
108
tls = task_local_storage ()
100
109
prev = delete! (tls, :SOURCE_PATH , nothing )
@@ -108,6 +117,7 @@ function reload_path(path)
108
117
tls[:SOURCE_PATH ] = prev
109
118
end
110
119
end
120
+ put (package_locks[path],nothing )
111
121
nothing
112
122
end
113
123
0 commit comments