# Notifications getting lost

**URL:** <https://clarionhub.com/t/notifications-getting-lost/7621>\
**Category:** questions\
**Tags:** threads\
**Created:** [October 30, 2024, 9:34am UTC](https://clarionhub.com/t/notifications-getting-lost/7621 "2024-10-30T09:34:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fred](https://clarionhub.com/letter_avatar_proxy/v4/letter/f/db5fbb/32.png) [@fred](https://clarionhub.com/u/fred)\
**Post date:** [October 30, 2024, 9:34am UTC](https://clarionhub.com/t/notifications-getting-lost/7621/1 "2024-10-30T09:34:48Z")

</div>

I have code that sends notifications from thread A to thread B. Works fine... generally.

However - some of the code in thread A is in quite tight/fast loops, so it often happens that MANY notifications a second are sent to thread B. It seems as if some get lost, i.e. thread B's code does not detect some of them (even with the LIFO nature kept in mind).

If I (experimentally) build delays into thread A's loops to slow it down somewhat, thread B receives them all again.

Any ideas why this could happen?

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [October 30, 2024, 2:17pm UTC](https://clarionhub.com/t/notifications-getting-lost/7621/2 "2024-10-30T14:17:43Z")

</div>

Maybe you’re pushing the notification paradigm more than most folks do?  
Are you doing a lot of work in the NOTIFICATION event?  
I wonder if queueing up the notifications (in a queue), and processing them in another event would help any.

Maybe you would find the Capesoft GUTS library to be useful. It’s pretty neat, and it’s $0.00.  
[https://www.capesoft.com/accessories/gutssp.htm](https://www.capesoft.com/accessories/gutssp.htm)

---

<div class="post-metadata">

**Author:** ![RchdR](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/d78d45/32.png) [@RchdR](https://clarionhub.com/u/RchdR)\
**Post date:** [October 30, 2024, 4:47pm UTC](https://clarionhub.com/t/notifications-getting-lost/7621/3 "2024-10-30T16:47:12Z")

</div>

> [@fred](#):
>
> If I (experimentally) build delays into thread A’s loops to slow it down somewhat, thread B receives them all again.

Welcome to theading and cpu time slicing! 😁😮‍💨

Your loop is hogging all the resources and not letting other parts of the runtime or os run properly.

Yield only works on intel cpus with hyperthreading switched on, sleep is an option at the end of the loop.

This thread [1] can shed some light, but I cant find the windows apis that handle notification, google keeps giving me the toaster notification api’s.

One other option is go back to the cooperative threadibg model ie \<c6 threading model, but you wont have notify to use.

You could post code to help us not guess possibilities, but another trick would be to go into control panel, system icon, select advanced system settings, advanced tab, performance settings button, advances tab, select background services if not already, click ok then reboot. That takes cpu time away from your loop and lets other parts of windows and other apps get more cpu time. This might help your two threads, but it depends on how sv have implementated notify in the runtime.

[1]

> [@Does an api exist that combines sleep(x) and yield?](https://clarionhub.com/t/does-an-api-exist-that-combines-sleep-x-and-yield/7568):
>
> Im using yield and sleep(x) inside a loop to hand back cpu time to background processes. Problem is Yield hands back to the OS without sleeping and sleep(x) just puts the thread to sleep without handing back to the OS. Problem is Im starting lots of new threads which do little jobs. If I use Sleep(x) before yield, they all sleep but theres no guarantee the background apps/processes will get the extra cpu time. This is made worse if Ive started a thread with a higher priority as the MS docs sug…

Edit. As there is a good chance these two threads are running on seperate cores, another trick you could try is bind your app to one cpu core as well.

> **[SetThreadAffinityMask function (winbase.h) - Win32 apps](https://learn.microsoft.com/en-gb/windows/win32/api/winbase/nf-winbase-setthreadaffinitymask?redirectedfrom=MSDN)**
>
> Sets a processor affinity mask for the specified thread.

I think Dries did a global ext template that did this for you. Thats worth a try, but if lots of work, the cpu might clock back its speed to handle one core getting too hot. Ymmv.

I also dont know if windows alters cpu scheduling or gives more cpu time to the other cores to balance the temperatures across cores. That would be a nice feature if windows did that!
