Multi-threading issues
- Issue
- Roland Smith
- PowerBuilder
- Friday, 19 January 2024 04:07 AM UTC
PB 2022 R3
I have a non-visual app that receives messages over Winsock and then processes the data and stores it in a database.
I first create an eight occurrence array of sharedobjects. I have an instance object (named Callback) that tracks whether the objects are busy with an instance boolean array.
To process each message I first check each of the eight to find the first one that isn't busy. I set it to busy, pass Callback to the background object (where it is saved to an instance variable), and then post the processing function. At the end of the processing function, I post a call to a function within Callback that is supposed to update the boolean marking the object as free.
Unfortunately, in the main thread, the boolean never gets updated so it runs into an all threads busy error.
I put logging in the callback function and it does write to the log. It seems like it is going to an alternate copy of the callback object.
My question then is how can the main thread receive notification from the background thread? This app has no windows, just non-visual objects.
I tried getting the handle of Callback so I could trigger an event using the Send function. The Handle function returns zero. I'm starting to wonder if I should use a hidden window.
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.