Created
June 15, 2016 11:52
-
-
Save simopal6/fe33bf98ec56da5a92e803ec018320a1 to your computer and use it in GitHub Desktop.
Torch thread serialization of tables with custom metatables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Create table with metatable | |
tab = {} | |
idx = {a = 1} | |
setmetatable(tab, {__index = idx}) | |
-- Setup threads | |
threads = require 'threads' | |
threads.Threads.serialization('threads.sharedserialize') -- Commenting this does not affect the outcome | |
pool = threads.Threads(2) | |
-- Prepare job | |
do | |
-- Setup upvalues | |
local tab_up = tab | |
local tab_mt_up = getmetatable(tab) | |
-- Add job | |
pool:addjob(function() | |
print("T1: tab_up.a (before setmetatable): " .. tostring(tab_up.a)) -- nil | |
setmetatable(tab_up, tab_mt_up) | |
print("T1: tab_up.a (after setmetatable): " .. tostring(tab_up.a)) -- 1 | |
end) | |
end | |
-- Clean exit | |
pool:synchronize() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment