andresy/torch — Issue #7: dokindex.lua is not thread-safe
Author: pflaquerre
Created: 2012-01-19 16:03:44+00:00
State: open

I've been building torch 7 with the following:

> cd torch7
> mkdir -p ./{build,install}.dbg
> pushd build.dbg
> cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../install.dbg -DINTEL_COMPILER_DIR=/opt/intel/Compiler/11.1/069/ ..
> make -j12 install
> popd

but sometimes (not always) end up with a corrupted build.dbg/dokindex.lua:

> sections["Introduction"] = {rank=0, packages={}}
> s["Introduction"].packages["install"] = {title="Installation Instructions", rank=1}
> sections["QT Interface"].packages["qt"] = {title="Lua executable and QT classes generic interface", rank=1}
> sections["QT Interface"].packages["qtide"] = {title="QT IDE for Lua", rank=111111}

If you look at scripts/dokindex.lua, you'll see that everyone could be writing to dokcurrentindex at the same time:

> local f = io.open(dokcurrentindex)
> if f then
> dofile(dokcurrentindex)
> f:close()
> end
>
> -- add new (given) section
> sections[section] = sections[section] or {rank=ranksec, packages={}}
> sections[section].packages[package] = {title=title, rank=rankpkg}
> sections[section].rank = math.min(sections[section].rank, ranksec)
>
> -- write all the stuff on disk so we can reload it easily
> local f = io.open(dokcurrentindex, 'w')
> for secname, section in pairs(sections) do
> f:write(string.format('sections["%s"] = {rank=%d, packages={}}\n', secname, section.rank))
> for pkgname, package in pairs(section.packages) do
> f:write(string.format('sections["%s"].packages["%s"] = {title="%s", rank=%d}\n', secname, pkgname, package.title, package. rank))
> end
> end
> f:close()

where dokcurrentindex is the same for most targets.