# Enter program from different threads

**URL:** <https://discuss.ocaml.org/t/enter-program-from-different-threads/2753>\
**Category:** Learning\
**Created:** [October 22, 2018, 2:43pm UTC](https://discuss.ocaml.org/t/enter-program-from-different-threads/2753 "2018-10-22T14:43:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wokalski](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/wokalski/32/38_2.png) [@wokalski](https://discuss.ocaml.org/u/wokalski)\
**Post date:** [October 22, 2018, 2:43pm UTC](https://discuss.ocaml.org/t/enter-program-from-different-threads/2753/1 "2018-10-22T14:43:03Z")

</div>

Part of my program does changes to the UI and that needs to be done on the main thread, but I want to do the rest on a background thread. Is it safe to enter an OCaml program from C using two different threads provided I’m careful not to enter it from thread A while it’s executing on thread B?

---

<div class="post-metadata">

**Author:** ![dbuenzli](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dbuenzli/32/18_2.png) [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Post date:** [October 22, 2018, 3:00pm UTC](https://discuss.ocaml.org/t/enter-program-from-different-threads/2753/2 "2018-10-22T15:00:03Z")

</div>

AFAIK it should be as long as you follow the `caml_{release,acquire}_runtime_system` dance.

You need to make sure however that the threads are known to the runtime system using `caml_c_thread_register()`.

See the [manual](https://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec476) for more details.
