Threading

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

makeshyft
Posts: 221
Joined: Mon Apr 15, 2013 4:41 am
Contact:

Re: Threading

Post by makeshyft » Tue Feb 11, 2014 4:56 am

I want to ressurect this thread on....threading

has anyone successfully used the technique in this thread?

Lets talk about threading ...... and does anyone know what the plans are for this in the future?
Founder & Developer @ MakeShyft R.D.A - https://www.makeshyft.com
Build Software with AppStarterStack for Livecode - https://www.AppStarterStack.com
Save Time with The Time Saver's Toolbox - https://www.TimeSaversToolbox.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Threading

Post by FourthWorld » Tue Feb 11, 2014 5:15 am

Threading can be tricky; LiveCode normally protects us from most race conditions. What you do need to do?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

makeshyft
Posts: 221
Joined: Mon Apr 15, 2013 4:41 am
Contact:

Re: Threading

Post by makeshyft » Tue Feb 11, 2014 5:51 am

Well, this isn't so much a current need that I have (...... I'm thinking of the livecode engine in general. We have big plans for it ...so I'm taking the time to learn about the engine at the level of its source...... Just starting on this .....so I'm trying to wrap my head around the current engine features and limitations.

I guess the question I have at this point is if there is any kind of inherent difficulty in implementing this? .... or if its just one of the things we haven't gotten to but will.

I image there are ways of running more than one instance of the engine, as standalones, and assign processors to them in some other way via the OS...and to have some way that the stacks talk together.
Founder & Developer @ MakeShyft R.D.A - https://www.makeshyft.com
Build Software with AppStarterStack for Livecode - https://www.AppStarterStack.com
Save Time with The Time Saver's Toolbox - https://www.TimeSaversToolbox.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Threading

Post by FourthWorld » Tue Feb 11, 2014 6:45 am

makeshyft wrote:I guess the question I have at this point is if there is any kind of inherent difficulty in implementing this?
Only the lack of a precedent to draw from in this family of languages. There's been interest in some circles, more than a little, but I've not yet seen any proposals for good syntax. Maybe that will be one of the outcomes of this thread.
I image there are ways of running more than one instance of the engine, as standalones, and assign processors to them in some other way via the OS...and to have some way that the stacks talk together.
Running multiple standalones seems to be a popular choice, esp. since they can be run facelessly so, with the small cost of a little extra RAM and some overhead beyond what even threading requires, it can get many parallel jobs done well enough.

The other method mentioned in this thread, using separate machines communicating over a simple prototocol like HTTP, is of course less efficient for small things, but opens the door for much bigger things, Hadoop-scale things. Some might say if you're doing a Hadoop-like job why not just use Hadoop, but I think there are possibly some nice things that can be done with LC in distributed systems.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

makeshyft
Posts: 221
Joined: Mon Apr 15, 2013 4:41 am
Contact:

Re: Threading

Post by makeshyft » Tue Feb 11, 2014 7:20 am

Very happy to hear your positive thoughts on this and that its possible to successfully use whats available now .... looking forward to working on some more advanced things after the current development work wraps up. Thanks and Cheers
Founder & Developer @ MakeShyft R.D.A - https://www.makeshyft.com
Build Software with AppStarterStack for Livecode - https://www.AppStarterStack.com
Save Time with The Time Saver's Toolbox - https://www.TimeSaversToolbox.com

SirWobbyTheFirst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 246
Joined: Tue Jun 30, 2009 11:15 pm

Re: Threading

Post by SirWobbyTheFirst » Thu Feb 13, 2014 5:01 pm

Hi Richard.

The only problems with using multiple processes to do something threads could do is that they not only generate a lot of overhead with an x86 chip (Something to do with the way memory management works with the MMU chip in x86 causes a lot of slowdown for operations which would otherwise be instant on other architectures) but there is very little in the way of examples for the Open, Read, Write, Close Process commands and if one does go down this route they are left to choose from the following forms of IPC:

1). Sockets based communication - Use sockets to talk between processes, slightly infeasible due to the possibility of a firewall blocking even localhost communication and of course the paranoia of todays users that the NSA has wriggled its way into software and a port being seen as a backdoor, also if you want to do a slave for each action thing, then it is also infeasible due to the inability for apps to use the same socket.
2). File based communication - Using files in a temporary folder to communicate, also slightly infeasible due to the requirement of having a loop enabled to read and write to a file constantly introduces a delay based on how long it takes for the engine to fire that loop again. Believe me I've tried, anything less than 30 ticks, caused a skip half the time.
3). Read and Write Process - As mentioned earlier, infeasible due to the lack of examples of how to pull it off properly, also requires a loop to listen for commands being sent as there is no direct notification that you have messages written to your STDIN.
4). Command line arguments - Also infeasible as whilst the arguments are good for one use, you will have to close the slave process and reload with new arguments, thus introducing that overhead on the processor and inevitably leading the user to believe your application is bad for his/her computer because (Ahem) "ur tkn away muh megahurz" because his laptop only has a dual core and all those Internet Explorer toolbars are being starved because your app got a little busy.

For me, a nice way to implement threads may be to keep it single threaded unless the developer specifically wants to use a thread, for example for my apps I might have the app itself running normally on the single thread that the engine is spawned with at startup and then fire up a new thread whenever the user wishes to do something that would be better served by a thread such as file I/O, copying a large file/folder or downloading a file from a server.

As for the syntax, maybes it could be a simple Create Thread command that works a little like the Do command in that you specify a bunch of crap to execute or a function/statement name to execute and the engine goes about executing that code on an alternate thread. I am contributing my thoughts merely because a lot of people see LC as not a real programming language due to the lack of many modern day programming constructs and the lack of threading is the one construct that always comes out but LC has many advantages over Java or C# for example like the lack of a need for a framework like .NET or the JVM or the ability to load and unload stacks at runtime.

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: Threading

Post by monte » Fri Feb 14, 2014 1:09 am

There's a couple of issues here. There's certainly lots of tasks that are currently blocking that would be quite nice if they weren't so adding `with message` options to those commands would help reduce the need to run whole chunks of LiveCode scripts on separate threads. A number of these may need to move to wait with messages style blocking in the near future anyway if you check the thread on the engine forum about that.

Then there's actually running a block of LiveCode script in a thread. Perhaps something like:

Code: Select all

dispatch <commandName> to <objectReference> [in background] with message <callback>
The callback is run on the main script thread. If in background isn't used then the command could be equivalent to send in -1 milliseconds but with nicer syntax and a callback.
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Threading

Post by mwieder » Tue Mar 11, 2014 10:42 pm

There's an interesting discussion on threading in an xtalk world over at
https://groups.yahoo.com/neo/groups/sta ... s/messages

Post Reply