How to do interthread communication?

73 views
Skip to first unread message

HaxeL

unread,
Nov 9, 2016, 12:31:18 PM11/9/16
to Haxe
Hi,

Has anybody tried/has code sample to demonstrate thread communication using sendMessage and receiveMessage api?

Kind Regards,
HaxeL

Constantine

unread,
Nov 9, 2016, 1:28:26 PM11/9/16
to Haxe

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Hugh

unread,
Nov 10, 2016, 12:00:13 AM11/10/16
to Haxe
There is also this:

And similarly, the hxcpp build tools uses multiple threads to do the compiling:

And uses a companion thread to each compiler thread to read the stderr of a process while one thread is reading stdout to avoid blocking:

posting the results back when done.

Hugh

HaxeL

unread,
Nov 10, 2016, 5:24:56 AM11/10/16
to Haxe
Thanks for your help but I need a simple example to learn and apply it.
I am a newbie and I can't spend time to dig into such a large code due to other constraints. I'm only evaluating the language.

I need two haxe classes each running a thread and one class sending a complex data structure for example a list, deque etc to another thread. This data structure must be a member of the class which sends the message. It must work!

Thanks again!

Kind Regards,
HaxeL

Constantine

unread,
Nov 10, 2016, 5:30:43 AM11/10/16
to Haxe
Ok then take a look this one http://old.haxe.org/doc/neko/threads

HaxeL

unread,
Nov 10, 2016, 5:48:43 AM11/10/16
to Haxe
Ok, I've attached the files from my project, it is Haxe cpp. Could anybody tell me the mistake I might be doing. The program crashes on each run.

Thanks,
HaxeL
Consumer.hx
Main.hx
Producer.hx

Constantine

unread,
Nov 10, 2016, 6:11:02 AM11/10/16
to Haxe
that code is mind blowing 

public function new(c: Thread) 
{
data = 0;
mutex = new Mutex();
doWork = true;
list = new List<Float>();

cThread = c;

var t1 = Thread.create(processInt);
myThread = Thread.create(processList);
cThread.sendMessage(myThread);
cThread.sendMessage(list);
}

Read that manual http://old.haxe.org/doc/neko/threads  please

HaxeL

unread,
Nov 10, 2016, 8:04:33 AM11/10/16
to Haxe
I've read the example but it is running in the same class. I want to run it across classes.

I did try various possibilities but it never worked, it so happened that I posted a code which contained a line which shouldn't have been there: cThread.sendMessage(myThread); I can't say if this is the only error I've made.

Please enlighten me what's wrong about that part of the code or anywhere in the code which I posted earlier. I've no experience with interpreted languages and that too with Haxe which is far away from my competences. And in my domain, there is no place for interpreted languages.

I don't want to be rude but, frankly, if it is that hard for anyone in the community to explain to new comers, learner, it becomes very easy for me to write it off in my evaluation. For a language that exists since 10 years and examples hard to find, I wouldn't even bother if it wasn't for the community support.

Look at Qt on the other hand, tonnes of examples and information on the web.

Thanks in advance if you can spare a few mins to help.

HaxeL

unread,
Nov 10, 2016, 11:15:13 AM11/10/16
to Haxe
I'm glad to share that I found the problems, fixed them and now my program is running.

Changes:
Producer.hx
cThread.sendMessage(myThread); //Removed
cThread.sendMessage(list); // Doesn't matter if it is there or not


Consumer.hx
var list:List<Float> = Thread.readMessage(true); // arg changed from false to true

I hope this helps others.

Thanks !
HaxeL

Rafael Oliveira

unread,
Nov 10, 2016, 11:38:30 AM11/10/16
to Haxe
About haxe examples in general, you can take a look here: 

and there is some examples too in http://try.haxe.org/
Reply all
Reply to author
Forward
0 new messages