Skip to content

Bug when queued functions return both nil and non-nil values #98

Description

@aschoenauer-sebag

Hi,

Here is the code snippet that reproduces the bug:

local Threads = require 'threads'
Threads.serialization('threads.sharedserialize')
opt={}
opt.nDonkeys= 2
do -- start K datathreads (donkeys)
   if opt.nDonkeys > 0 then
      local options = opt -- make an upvalue to serialize over to donkey threads
      donkeys = Threads(
         opt.nDonkeys,
         function(threadid)
            require 'torch'
         end,

         function()
         end
      );
   else -- single threaded data loading. useful for debugging
      donkeys = {}
      function donkeys:addjob(f1, f2) f2(f1()) end
      function donkeys:terminate() end
   end
end

for k=1,10 do
    donkeys:addjob(
           function()
               local var1
               local var2 = 2
               if __threadid==1 then var1 = 1 end
               return var1, var2
           end,
                   function(var1, var2) print(var1, var2) end)
end
donkeys:terminate()

With opt.nDonkeys=2 we get:

t7> dofile('sandbox.lua' )
1	2	
nil	nil	
1	2	
nil	nil	
1	2	
nil	nil	
1	2	
1	2	
1	2	
nil	nil	

when I think it's reasonable to be expecting

t7> dofile('sandbox.lua' )
1	2	
nil	2	
1	2	
nil	2	
1	2	
nil	2	
1	2	
1	2	
1	2	
nil	2	

If this was done on purpose I would be curious to know why.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions