I'm using the threads package to create a thread pool. When I initiate the thread pool, I call require 'image' for each thread. Sometimes this causes the program to freeze up. If the number of threads is small, the freezing is less likely. If it is large, the freezing happens almost every time. Below is a minimal example with 6 threads. For me, this freezes up about half the time:
local threads = require 'threads'
threads.serialization('threads.sharedserialize')
local num_threads = 6
local pool = threads.Threads(
num_threads,
function(thread_ID)
print(thread_ID .. ' before')
require 'image'
print(thread_ID .. ' after')
end
)
print 'DONE'
If the number of threads is increased to 10, it freezes up essentially every time. I don't know if this problem is specific to the image package. I have torch, threads and image packages up-to-date. I am using Ubuntu16.04.