# Callbacks in Threads not Called

**URL:** <https://forum.legato.io/t/callbacks-in-threads-not-called/5994>\
**Category:** Legato Application Framework\
**Created:** [October 8, 2021, 3:50pm UTC](https://forum.legato.io/t/callbacks-in-threads-not-called/5994 "2021-10-08T15:50:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![simon.naegele](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@simon.naegele](https://forum.legato.io/u/simon.naegele)\
**Post date:** [October 8, 2021, 3:50pm UTC](https://forum.legato.io/t/callbacks-in-threads-not-called/5994/1 "2021-10-08T15:50:03Z")

</div>

Hi,

i have to applications that are connect via IPC.  
The client uses a thread which calls `server_ConnectService` and then a function like `server_dowork(callbackFunc)`.  
The problem is that the `callbackFunc` doesn’t get called. If I move the `server_dowork(callbackFunc)` outside of the thread, everything works as expected and `callbackFunc` is called after work is done.

Why does a callback not work in a thread?

What am I missing here?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [October 9, 2021, 1:13am UTC](https://forum.legato.io/t/callbacks-in-threads-not-called/5994/2 "2021-10-09T01:13:49Z")

</div>

Does this application work for server to call the callback function in client?

> [@Cannot get callback between components (IPC) to work properly](https://forum.legato.io/t/cannot-get-callback-between-components-ipc-to-work-properly/4653/2):
>
> you can refer to my application.[IPC\_step4.rar](https://forum.legato.io/uploads/short-url/syTZydAV5mv0Ydf7OXQe8cI8euc.rar) (303.8 KB)

---

<div class="post-metadata">

**Author:** ![simon.naegele](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@simon.naegele](https://forum.legato.io/u/simon.naegele)\
**Post date:** [October 11, 2021, 10:27am UTC](https://forum.legato.io/t/callbacks-in-threads-not-called/5994/3 "2021-10-11T10:27:47Z")

</div>

> [@jyijyi](#):
>
> Does this application work for server to call the callback function in client?

As I said: it only does if the callback is called outside a thread.

I had a look at the IPC\_step4, but this seems to a lot of code that I don’t want to implement, since I only need a simple callback.

So the question remains: why is the callback not working in the thread?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [October 11, 2021, 3:18pm UTC](https://forum.legato.io/t/callbacks-in-threads-not-called/5994/4 "2021-10-11T15:18:39Z")

</div>

I don’t see problem with legato 20.04 on WP76.

[IPC\_step4\_thread.rar](https://forum.legato.io/uploads/short-url/mNRADcaeSNuitT77OHBJ60rQENe.rar) (3.6 KB)

---

<div class="post-metadata">

**Author:** ![simon.naegele](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@simon.naegele](https://forum.legato.io/u/simon.naegele)\
**Post date:** [October 11, 2021, 5:53pm UTC](https://forum.legato.io/t/callbacks-in-threads-not-called/5994/5 "2021-10-11T17:53:58Z")

</div>

I can see that this is working, however as I said, I want to use simple callbacks and not events since events add a lot of code that I don’t want.

Please see my attached sample app that clearly shows that callbacks are not working if a thread is used.[callbackTest.zip](https://forum.legato.io/uploads/short-url/xWm8FsdENIEU1jfjnsMje7f8OzY.zip) (2.8 KB)

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [October 11, 2021, 9:37pm UTC](https://forum.legato.io/t/callbacks-in-threads-not-called/5994/6 "2021-10-11T21:37:39Z")

</div>

Better use event api() as it is proven to be working

I think the way you are using is not recommended.  
Here says circular dependency is not recommended to avoid deadlocks:

> [@IPC API interfaces binding queries](https://forum.legato.io/t/ipc-api-interfaces-binding-queries/2997/2):
>
> Hi, By default, each app runs in its own sandbox. When an app is constructed, all the IPC services it needs are declared. At runtime, the Supervisor and the Service Directory enforce that only those approved IPC services are accessed by the app. Approval is specified through “bindings”. Binding is between Client and Server. CLient -Server can be 2 applications or 2 components in application which are 2 different process. This dictates the need for bindings. Check this link ([Application Defini…](http://legato.io/legato-docs/latest/defFilesAdef.html#defFilesAdef_bindings)
