diff options
author | Kaiyu Yang <yangky11@outlook.com> | 2015-10-04 08:39:37 +0300 |
---|---|---|
committer | Kaiyu Yang <yangky11@outlook.com> | 2015-10-04 08:39:37 +0300 |
commit | b3d8fb70bf573c5d4c3818e9b6b7c573a03829d5 (patch) | |
tree | 44dfbea281a153ce84393dc99e859b43d1e9d77b | |
parent | 7c5ff00fa98825cd477eb767fb7dc0832592f61c (diff) |
first commit
-rw-r--r-- | README.md | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -206,6 +206,38 @@ threads.Threads(4, ``` Note that the id of each thread is also stored into the global variable `__threadid` (in each thread Lua state). +Special notice about upvalues: +When a child deserialize a callback, all the upvalues in it must be of known types. Since the callbacks in threads.Threads are deserialized in order, +we suggest that you make a separated f1 containing all the definitions and put the other code in f2,f3,... +For example +``` +require 'nn' +local threads = require 'threads' +local model = nn.Linear(5, 10) +threads.Threads( + 2, + function(idx) + require 'nn' + local myModel = model:clone() -- This code will crash, because the upvalue 'model' is of unknown type before deserialization + end +) +``` + +``` +require 'nn' +local threads = require 'threads' +local model = nn.Linear(5, 10) +threads.Threads( + 2, + function(idx) + require 'nn' + end, + function(idx) + local myModel = model:clone() -- This code is OK. child threads know nn.Linear when deserializing f2 because f1 has already been executed + end +) +``` + <a name='threads.specific'/> #### Threads:specific(boolean) #### |