Lua ForkThread / MultiTreading - Accessing data

Everything about mods can be found here.

Moderator: Morax

Lua ForkThread / MultiTreading - Accessing data

Postby Franck » 06 Mar 2016, 21:49

Hi,

I'm still working on my mod, and i asking myself if i need to worry about accessing variable between my threads.

I currently wrote a thread (with ForkThread) that erase a datatable each 2s. This datatable is modified outside my thread. For now, i run my erasing thread only when the datatable is not being modified.

But i m asking if i need to worry myself, as it seems that lua is not really multithreaded capable. I've got no error when i access my datatable anywhere anytime by any of my thread.

Am i lucky, or is lua not really multithreading capable, or should i take care (i found no documentation about the ForkThread function) ?

Any idea ? It should reduce the time i need to develop my mod.
Franck
Crusader
 
Posts: 28
Joined: 24 Dec 2015, 16:16
Has liked: 1 time
Been liked: 1 time
FAF User Name: Franck

Re: Lua ForkThread / MultiTreading - Accessing data

Postby nine2 » 06 Mar 2016, 23:37

I think it's not a real thread, just a trick. Otherwise couldn't stay in sync?
nine2
Councillor - Promotion
 
Posts: 2416
Joined: 16 Apr 2013, 10:10
Has liked: 285 times
Been liked: 515 times
FAF User Name: Anihilnine

Re: Lua ForkThread / MultiTreading - Accessing data

Postby Franck » 07 Mar 2016, 00:14

Ty for your reply Ani. This time i need threads to catch information by time (in my case every 2 s) in the simside.
In fact i hooked the DoTakeDamage function. And i can't put a Waitseconds() function. It seems that you can't call Waitseconds() functions everywhere. It's logical, you can't slow the process.

But my thread is working well, i was just wondering if need to spend time to take care of shared variables. If lua threading is a trick, maybe not ^^
Franck
Crusader
 
Posts: 28
Joined: 24 Dec 2015, 16:16
Has liked: 1 time
Been liked: 1 time
FAF User Name: Franck

Re: Lua ForkThread / MultiTreading - Accessing data

Postby nine2 » 07 Mar 2016, 00:32

Think you can't WaitSeconds unless you are in a forked thread. Maybe you can't do it sim side not sure.

Yeah - don't worry about shared variables... you don't have to lock them.
nine2
Councillor - Promotion
 
Posts: 2416
Joined: 16 Apr 2013, 10:10
Has liked: 285 times
Been liked: 515 times
FAF User Name: Anihilnine

Re: Lua ForkThread / MultiTreading - Accessing data

Postby Franck » 07 Mar 2016, 08:56

As i do in my mod, you can call Waitseconds() in simside with ForkThreads which is very usefull. Because SimSide is by event leaded, and a timed thread can be usefull.
Franck
Crusader
 
Posts: 28
Joined: 24 Dec 2015, 16:16
Has liked: 1 time
Been liked: 1 time
FAF User Name: Franck

Re: Lua ForkThread / MultiTreading - Accessing data

Postby Crotalus » 07 Mar 2016, 11:08

Yup, "threads" in this case are really lua coroutines so they never run truly in parallel, instead they yield while another coroutine run.
Crotalus
Priest
 
Posts: 319
Joined: 27 Jan 2013, 20:37
Has liked: 2 times
Been liked: 102 times
FAF User Name: Crotalus

Re: Lua ForkThread / MultiTreading - Accessing data

Postby Franck » 08 Mar 2016, 10:03

Ty Crotalus for for yr reply.
Franck
Crusader
 
Posts: 28
Joined: 24 Dec 2015, 16:16
Has liked: 1 time
Been liked: 1 time
FAF User Name: Franck


Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest