Skip to content

Commit

Permalink
fix #3383
Browse files Browse the repository at this point in the history
The problem was the scheme for numbering LambdaStaticDatas to avoid
recompiling the same closure on remote machines. Only the remote side
kept state, so if a LambdaStaticData was GC'd on the local side we
could start reusing IDs incorrectly.
  • Loading branch information
JeffBezanson committed Aug 27, 2013
1 parent 7f1522b commit 7b427b5
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions base/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,6 @@ function serialize(s, m::Module)
serialize(s, fullname(m))
end

function lambda_number(l::LambdaStaticData)
# a hash function that always gives the same number to the same
# object on the same machine, and is unique over all machines.
hash(uint64(object_id(l))+(uint64(myid())<<44))
end

function serialize(s, f::Function)
writetag(s, Function)
name = false
Expand Down Expand Up @@ -206,6 +200,21 @@ function serialize(s, f::Function)
end
end

const lambda_numbers = WeakKeyDict()
lnumber_salt = 0
function lambda_number(l::LambdaStaticData)
global lnumber_salt, lambda_numbers
if haskey(lambda_numbers, l)
return lambda_numbers[l]
end
# a hash function that always gives the same number to the same
# object on the same machine, and is unique over all machines.
ln = hash(lnumber_salt+(uint64(myid())<<44))

This comment has been minimized.

Copy link
@vtjnash

vtjnash Aug 28, 2013

Member

shouldn't this be a uint128, if you actually want to guarantee uniqueness? or possibly a uint64 assigned as follows:
ln = uint32(hash(uint32(lnumber_salt))) + uint64(myid())<<32
assuming that myid()::Int32

lnumber_salt += 1
lambda_numbers[l] = ln
return ln
end

function serialize(s, linfo::LambdaStaticData)
writetag(s, LambdaStaticData)
serialize(s, lambda_number(linfo))
Expand Down

0 comments on commit 7b427b5

Please sign in to comment.