PB 2022
I have a multi-threaded app (using SharedObject functions) that is non-visual, it receives requests via Winsock and creates a background thread to process the request.
I'm getting hang-ups when it gets a lot of requests all at once. I suspect it has to do with notifying the main thread that the background thread is done.
Here is how it works:
I have a 'callback' object that is defined as a global variable with the name gnv_callback.
This is the code that launches the background thread. Callback is a function argument name. I encapsulated the SharedObjectRegister/SharedObjectGet into the CreateSharedObject function in the Callback object. In the lnv_Request object, SetCallback saves a reference to Callback in an instance variable.
// register the shared object
ler_result = Callback.CreateSharedObject(lnv_Request, ls_InstanceName)
If ler_result = Success! Then
// call functions in the shared object
lnv_Request.SetSocket(ClientSocket)
lnv_Request.SetCallback(Callback)
lnv_Request.Post Process_Request(ls_InstanceName, RequestNbr)
Else
The Process_Request function will perform the business code and when done it has the following:
// Shutdown the client socket
shutdown(ClientSocket, SD_SEND)
// Notify the main thread that the request is done
Callback.Post NotifyDone(InstanceName)
NotifyDone is just this:
SharedObjectUnregister(InstanceName)
Now I am wondering if there is a better way to unregister the shared object without causing blocking of the main thread.
InstanceName = "Request" + String(RequestNbr)