# Move control back to haxe thread without registering

**URL:** https://community.haxe.org/t/move-control-back-to-haxe-thread-without-registering/4210
**Category:** Haxe
**Tags:** haxe-cpp
**Created:** [March 27, 2024, 5:20am UTC](https://community.haxe.org/t/move-control-back-to-haxe-thread-without-registering/4210 "2024-03-27T05:20:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![singpolyma](https://community.haxe.org/user_avatar/community.haxe.org/singpolyma/32/2193_2.png) [@singpolyma](https://community.haxe.org/u/singpolyma)
#### Post date: [March 27, 2024, 5:20am UTC](https://community.haxe.org/t/move-control-back-to-haxe-thread-without-registering/4210/1 "2024-03-27T05:20:22Z")

</div>

Is it possible to move control from a thread created by a C++ library, back to a Haxe thread, without registering the foreign thread with the GC using SetTopOfStack? Ideally I just want the smallest thing I can do, push to a sync queue, trigger EventLoop, something like this that would move control back so haxe code can run where it belongs.

---

<div class="post-metadata">

### Author: ![player\_03](https://community.haxe.org/user_avatar/community.haxe.org/player_03/32/821_2.png) [@player\_03](https://community.haxe.org/u/player_03)
#### Post date: [July 10, 2024, 6:29pm UTC](https://community.haxe.org/t/move-control-back-to-haxe-thread-without-registering/4210/2 "2024-07-10T18:29:19Z")

</div>

Sorry for the late reply, but one simple option is `haxe.MainLoop.runInMainThread(myFunction)`. This assumes the C++ library has already called a Haxe function, and the problem is the Haxe function is running on the wrong thread. I’m not familiar with the GC, so I can’t help you with that part.
