diff options
author | Soumith Chintala <soumith@gmail.com> | 2015-10-21 18:46:35 +0300 |
---|---|---|
committer | Soumith Chintala <soumith@gmail.com> | 2015-10-21 18:46:35 +0300 |
commit | 203972852a877d3f623b8dd4a84e669b2a1e544e (patch) | |
tree | 9a03ce181658e2674706793f263793af8f929d2b | |
parent | 37b1e723874fa1ab8a5fb26519e2e9a2cd8dbd7e (diff) | |
parent | 2164792216a033e3c9e086acfde00d28ac26797f (diff) |
Merge pull request #29 from yangky11/add-notice-about-upvalues-in-README
Add notice about upvalues in readme
-rw-r--r-- | README.md | 32 |
1 files changed, 31 insertions, 1 deletions
@@ -205,7 +205,37 @@ threads.Threads(4, ) ``` -Note that the id of each thread is also stored into the global variable `__threadid` (in each thread Lua state). +Note that the id of each thread is also stored into the global variable `__threadid` (in each thread Lua state). +Notice about Upvalues: +When deserializing a callback, upvalues must be of known types. Since `f1,f2,...` in [threads.Threads()](#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,...`. e.g. +``` +require 'nn' +local threads = require 'threads' +local model = nn.Linear(5, 10) +threads.Threads( + 2, + function(idx) -- This code will crash + require 'nn' -- because the upvalue 'model' + local myModel = model:clone() -- is of unknown type before deserialization + end +) +``` + +``` +require 'nn' +local threads = require 'threads' +local model = nn.Linear(5, 10) +threads.Threads( + 2, + function(idx) -- This code is OK. + require 'nn' + end, -- child threads know nn.Linear when deserializing f2 + function(idx) + local myModel = model:clone() -- because f1 has already been executed + end +) +``` + <a name='threads.specific'/> #### Threads:specific(boolean) #### |