potential race condition: require 'image'

16 views
Skip to first unread message

Alexander Weiss

unread,
Jun 23, 2016, 2:32:34 PM6/23/16
to torch7
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.

Alexander Weiss

unread,
Jun 23, 2016, 3:40:41 PM6/23/16
to torch7
This appears to be system dependent.  I tried the same code on an Ubuntu 14.04 system, and it never freezes.  (Both of my systems are on AWS.)

soumith

unread,
Jun 23, 2016, 11:28:18 PM6/23/16
to torch7 on behalf of Alexander Weiss
Hmmm, I'm not able to reproduce it either. A hack for this weirdness can be a mutex around the "require" calls (or even a small randomized sleep). I expect that something about the underlying dlopen that is called when "require 'image'" is being weird on your system.

--
You received this message because you are subscribed to the Google Groups "torch7" group.
To unsubscribe from this group and stop receiving emails from it, send an email to torch7+un...@googlegroups.com.
To post to this group, send email to tor...@googlegroups.com.
Visit this group at https://groups.google.com/group/torch7.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages