03-17-2022 04:23 AM
Hi!
I'm building a program that communicates with another device using network streams and variables. When the connection is down I attempt to reconnect every 1 second, using an AsyncTimer. The timer calls a callback, "tryCommunicate()" which in turn runs a couple of functions eventually resulting in a call to CNVCreateReader(). The documentation for CNVCreateReader states that having the function inside a callback can cause a deadlock - which I'm experiencing. So I need to extract the call to CNVCreateReader to outside callbacks, but I can't for the life of me figure out how that's supposed to happen.
This is probably a very common user case. How am I supposed to construct this without having CNVCreateReader in a callback in one way or another?
Thanks.
03-17-2022 04:51 AM
Create thread with an infinite loop (that you can terminate any time you want, of course) and inside it, check a global flag variable, which you set in the callback and if it is set then call your function and than reset it back in the thread.
Put some sleep in the loop not to overwhelm the cpu.
Hope this helps