Threads using System.io.Process

71 views
Skip to first unread message

Jelle Sebreghts

unread,
Dec 11, 2014, 6:39:49 AM12/11/14
to haxe...@googlegroups.com
I haven't written a single line of Haxe code yet so please bare with me, I'm still in the research fase.

Is it possible to use System.io.Process to create Threads (or something similar) in Haxe, and will it be cross-platform (I'm looking at you PHP, JavaScript, ...).
So basically: can you use System.io.Process to call other Haxe code, and if so, how? And will it spawn a separate thread?

Thanks in advance!
Jelle

Sam MacPherson

unread,
Dec 11, 2014, 8:07:51 AM12/11/14
to haxe...@googlegroups.com
You can't access threads in a language that doesn't support them (ie JavaScript). Threads are supported first-class in the neko and cpp targets in the class neko.vm.Thread or cpp.vm.Thread respectively. sys.io.Process is used to launch and manage child processes and is only available on "system" targets.

You should probably know that threading is not really a priority for Haxe. Although it is possible in some targets, the language is missing a lot of the high level concurrency features that lots of other languages have.

Jelle Sebreghts

unread,
Dec 11, 2014, 9:27:02 AM12/11/14
to haxe...@googlegroups.com
I feared as much, but it is of course understandable if you want to support so many platforms. Are there other workarounds that allow you do do something similar to threads (ie promises/async calls, ...) that is supported by all languages that Haxe can compile to?

Sam MacPherson

unread,
Dec 11, 2014, 9:53:58 AM12/11/14
to haxe...@googlegroups.com
Well again it depends on the target. Every target will support asynchronous callback/promises style, but not every target has an event loop like JS/Flash so you will need to roll your own for targets like neko, php, cpp, etc. Otherwise you will just get blocking calls for those targets.

Btw there is a nice cross-platform library for promises called "promhx".

Could I ask what you are trying to do? Maybe thinking in such low level terms is not really necessary for your project.

Jelle Sebreghts

unread,
Dec 11, 2014, 10:20:35 AM12/11/14
to haxe...@googlegroups.com
I'm just looking at the Haxe language and seeing what its capabilities are.

In the (very) long run, I'd like to take a stab at converting the jsprit library (a VRP library written in Java, which uses threads) to Haxe so that I can use it on (almost) any platform (mainly PHP). But that is for if and when I find the time, as it would be a side project for my free time.

Sam MacPherson

unread,
Dec 11, 2014, 11:12:00 AM12/11/14
to haxe...@googlegroups.com
Well I am unfamiliar with the VRP, but if you wanted to solve it cross-platform while taking advantage of parallel processing you would likely have to find a common way between the targets to achieve this. Threads being the most flexible you may want to look at using the worker model that both Flash and JS use. From there you can implement workers on the threaded languages. This may or may not be possible depending on how jsprit is designed.

Raoul Duke

unread,
Dec 11, 2014, 12:32:02 PM12/11/14
to haxe...@googlegroups.com
Where's the cooperative threads library? CSP? Something? :-)
Reply all
Reply to author
Forward
0 new messages