Question about multi-threading and mutexes

83 views
Skip to first unread message

Horsetopus

unread,
Sep 22, 2016, 9:20:45 AM9/22/16
to Haxe
Hello. I have questions regarding Haxe (Neko target), and Multi-Threading.

So in haxe, this:
var cpt:Int;
Thread.create( function() { while( true ) cpt++; } ); //function1
Thread.create( function() { while( true ) cpt--; } ); //function2
builds, run, and work. Right? Except if both Thread try to access at the same time, and then anything goes. So it's a no go.

But what about objects with the mutex mechanic?
If I have a Buffer class ( some FIFO string array with a mutex to lock on writing and reading ), can I just read it from within the created thread, or do I have to send it through sendMessage?

Just reading it seams to work, from my tests. But I don't have the means to stress-test it with a lot of connections, and I am afraid it just works now as a simple boolean lock, while I suppose mutex are more reliable.

Anybody?
Thanks.

Max S

unread,
Sep 26, 2016, 7:25:04 AM9/26/16
to haxe...@googlegroups.com
If the Buffer class read/write/etc methods are mutexed, you should be fine in multithreaded environment - that's the whole point of having a mutex. Thread.sendMessage() is just another way of doing the same thing, synchronizing read/write access to data.

--
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.

Max S

unread,
Sep 26, 2016, 7:33:24 AM9/26/16
to haxe...@googlegroups.com
BTW, there's a neko.vm.Deque for you, too. Should do the same thing as your Buffer class.
Reply all
Reply to author
Forward
0 new messages