@@ -263,6 +263,7 @@ function parsed_toml(project_file::AbstractString, toml_cache::TOMLCache, toml_l
263
263
end
264
264
265
265
# # package identification: determine unique identity of package to be loaded ##
266
+ const require_lock = ReentrantLock ()
266
267
267
268
# Used by Pkg but not used in loading itself
268
269
function find_package (arg)
@@ -862,7 +863,7 @@ function _require_search_from_serialized(pkg::PkgId, sourcepath::String)
862
863
end
863
864
864
865
# to synchronize multiple tasks trying to import/using something
865
- const package_locks = Dict {PkgId,Condition} ()
866
+ const package_locks = Dict {PkgId,Threads. Condition} ()
866
867
867
868
# to notify downstream consumers that a module was successfully loaded
868
869
# Callbacks take the form (mod::Base.PkgId) -> nothing.
@@ -957,6 +958,7 @@ For more details regarding code loading, see the manual sections on [modules](@r
957
958
[parallel computing](@ref code-availability).
958
959
"""
959
960
function require (into:: Module , mod:: Symbol )
961
+ @lock require_lock begin
960
962
LOADING_CACHE[] = LoadingCache ()
961
963
try
962
964
uuidkey = identify_package (into, String (mod))
@@ -998,6 +1000,7 @@ function require(into::Module, mod::Symbol)
998
1000
finally
999
1001
LOADING_CACHE[] = nothing
1000
1002
end
1003
+ end
1001
1004
end
1002
1005
1003
1006
mutable struct PkgOrigin
@@ -1009,6 +1012,7 @@ PkgOrigin() = PkgOrigin(nothing, nothing)
1009
1012
const pkgorigins = Dict {PkgId,PkgOrigin} ()
1010
1013
1011
1014
function require (uuidkey:: PkgId )
1015
+ @lock require_lock begin
1012
1016
if ! root_module_exists (uuidkey)
1013
1017
cachefile = _require (uuidkey)
1014
1018
if cachefile != = nothing
@@ -1020,13 +1024,14 @@ function require(uuidkey::PkgId)
1020
1024
end
1021
1025
end
1022
1026
return root_module (uuidkey)
1027
+ end
1023
1028
end
1024
1029
1025
1030
const loaded_modules = Dict {PkgId,Module} ()
1026
1031
const module_keys = IdDict {Module,PkgId} () # the reverse
1027
1032
1028
- is_root_module (m:: Module ) = haskey (module_keys, m)
1029
- root_module_key (m:: Module ) = module_keys[m]
1033
+ is_root_module (m:: Module ) = @lock require_lock haskey (module_keys, m)
1034
+ root_module_key (m:: Module ) = @lock require_lock module_keys[m]
1030
1035
1031
1036
function register_root_module (m:: Module )
1032
1037
key = PkgId (m, String (nameof (m)))
@@ -1053,12 +1058,13 @@ using Base
1053
1058
end
1054
1059
1055
1060
# get a top-level Module from the given key
1056
- root_module (key:: PkgId ) = loaded_modules[key]
1061
+ root_module (key:: PkgId ) = @lock require_lock loaded_modules[key]
1057
1062
root_module (where :: Module , name:: Symbol ) =
1058
1063
root_module (identify_package (where , String (name)))
1064
+ maybe_root_module (key:: PkgId ) = @lock require_lock get (loaded_modules, key, nothing )
1059
1065
1060
- root_module_exists (key:: PkgId ) = haskey (loaded_modules, key)
1061
- loaded_modules_array () = collect (values (loaded_modules))
1066
+ root_module_exists (key:: PkgId ) = @lock require_lock haskey (loaded_modules, key)
1067
+ loaded_modules_array () = @lock require_lock collect (values (loaded_modules))
1062
1068
1063
1069
function unreference_module (key:: PkgId )
1064
1070
if haskey (loaded_modules, key)
@@ -1077,7 +1083,7 @@ function _require(pkg::PkgId)
1077
1083
wait (loading)
1078
1084
return
1079
1085
end
1080
- package_locks[pkg] = Condition ()
1086
+ package_locks[pkg] = Threads . Condition (require_lock )
1081
1087
1082
1088
last = toplevel_load[]
1083
1089
try
0 commit comments