lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> On Apr 13, 2018, at 5:28 PM, Sean Conner <sean@conman.org> wrote:
> 
>  Case 1---the state is stored in a static C variable.  Your program
> instantiates two separate Lua VMs (say, you are using then in different
> threads of the program).  As each thread runs, there will be calls
> interspaced to spc_rnd() between the two threads:
> 
>    thread-1    A
>    thread-2    B
>    thread-1    C
>    thread-1    D
>    thread-2    E
>    thread-1    F
>    thread-2    G
> 
> so thread1 will "see" the sequence "A C D F" and thread2 will "see" the
> sequence "B E G".
> 

Thanks Sean.
Your post showed that the random outputs may "skip"

Cloud-Wu (previous post) showed that it may "rewind"
(so even "A C D F" and "B E G" is not guaranteed)

-> storing states in C static variable is a bad idea.
(although it is simpler and much faster)

Only way it will work correctly is no threads, single lua state,
say, running lua.exe