Garbage collection in multithreaded app haxe/cpp

304 views
Skip to first unread message

Alexander Kuzmenko

unread,
Jun 11, 2013, 4:41:50 AM6/11/13
to haxe...@googlegroups.com
Hi! 
I want to create multithreaded game server and i need to know how to deal with garbage collection.
Do i need to handle it myself for each thread, or does hxcpp handle garbage collection for all threads?

AS3Boyan

unread,
Jun 11, 2013, 11:55:53 AM6/11/13
to haxe...@googlegroups.com
Maybe you already know this, but when thread has nothing to do it will be terminated...

Sam MacPherson

unread,
Jun 11, 2013, 1:59:47 PM6/11/13
to haxe...@googlegroups.com
If it is the same as the neko target (which I assume it is), then garbage collection will be handled in the same way as a single threaded application.

Raoul Duke

unread,
Jun 11, 2013, 2:08:23 PM6/11/13
to haxe...@googlegroups.com
i wouldn't assume it is. the neko and hxcpp code aren't related that
i've ever heard. and gc is very subjective. and hxcpp/nme has already
changed gc's at least once.
> --
> 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/groups/opt_out.
>
>

Hugh

unread,
Jun 12, 2013, 1:30:03 AM6/12/13
to haxe...@googlegroups.com
Hi,
Multi threads should work. But some things to note:
 - You must create the threads with hxcpp, not via a native "pthread_create" or whatever.
 - The threads must cooperate by registering when they are about to do a blocking operation.  The functions in the standard hxcpp libraries do this.
 - It may not scale infinitely well, but several threads should be fine
 - The basic structures are not locked. eg, take particular care with arrays, where multiple threads may push into the same array.

Hugh

Hugh

unread,
Jun 12, 2013, 1:32:10 AM6/12/13
to haxe...@googlegroups.com
Also forgot a few things that apply to all threaded apps.
 - opengl can only be accessed from the "main thread"
 - android native gui runs in its own thread, so you need to do some work to use it correctly.

Hugh

Alexander Kuzmenko

unread,
Jun 12, 2013, 3:41:19 AM6/12/13
to haxe...@googlegroups.com
Thanks! That's great!

Luca

unread,
Jun 12, 2013, 7:24:07 AM6/12/13
to haxe...@googlegroups.com
I've not had any problems in my work using opengl from multiple threads? Certainly there's no such restriction in standard c++ programming.

Hugh

unread,
Jun 12, 2013, 11:16:39 PM6/12/13
to haxe...@googlegroups.com
Hi,
On opengl, the gl calls refer to the "current context" and the "current context" is set per thead.  So you must load textures etc from a thread that has "MakeCurrent" called at some stage.  However, you can manipulate pixels and run physics etc from other threads - as long as the do not call the gl functions directly.

Hugh

Luca

unread,
Jun 13, 2013, 1:52:06 AM6/13/13
to haxe...@googlegroups.com
Well no, I mean having gl calls from multiple threads. As long as each thread has its own context it is perfectly safe (Eg. multiple windows)

Hugh

unread,
Jun 14, 2013, 1:22:05 AM6/14/13
to haxe...@googlegroups.com
Yes, fair enough.  I guess I am warning about NME not working as expected (since there is only 1 nme context)

Hugh
Reply all
Reply to author
Forward
0 new messages