Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Still having problem with the worker thread. #82

Open
andresantacruz opened this issue Feb 28, 2019 · 15 comments
Open

Still having problem with the worker thread. #82

andresantacruz opened this issue Feb 28, 2019 · 15 comments

Comments

@andresantacruz
Copy link

Hi,

I'm still having problem with the worker thread of the lib.

The thread sometimes just don't die properly upon ExitProcess.

What is the correct way to get the thread object so I can assure the thread to be dead before the main thread exits its execution?

@the1schwartz
Copy link
Contributor

Do you call GameAnalytics::onQuit() when quiting the application?

@the1schwartz
Copy link
Contributor

If you still have issues with the worker thread I can try to expose a method which tells if the thread has finished or not.

@andresantacruz
Copy link
Author

Do you call GameAnalytics::onQuit() when quiting the application?

Yes, I call endSession() and onQuit() when exiting the process. An important note here: I'm loading the lib in another DLL; if I call onQuit just before calling ExitProcess the GA's worker thread keeps alive whatsoever; strangly the GA's thread only shutdown if I call onQuit at DllMain (in PROCESS_DETAH) of my DLL (which is what I'm doing but still get the thread to keep alive sometimes). Does the function onQuit blocks execution untill the work is done or it works async?

If you still have issues with the worker thread I can try to expose a method which tells if the thread has finished or not.

IDK if that will help. I can create a spin loop to wait untill the thread is finished but the problem may be cause by other thing. Can you think of any possible execution flow in method onQuit() that doesn't kill the thread after few seconds? Does this method have a timeout mechanism? If not, this could work as a palliative solution while the real source of this problem can't be found. So user of the lib just spin loop after onQuit until the GA's thread is finished (which will be done either by the expected execution flow or by timeout).

@the1schwartz
Copy link
Contributor

When onQuit has been called an endThread flag is set to tell the worker thread to stop. Also see the logic here: https://github.com/GameAnalytics/GA-SDK-CPP/blob/master/source/gameanalytics/GAThreading.cpp#L141-L173

onQuit also tries to wait until the worker thread is finished: https://github.com/GameAnalytics/GA-SDK-CPP/blob/master/source/gameanalytics/GameAnalytics.cpp#L903-L928

So in theory is should stop with a couple of seconds. I have not tested the dll scenario but maybe I will test it out to see what goes wrong. If you have a simple test project where this issue is reproducible I will be happy to test with that.

@andresantacruz
Copy link
Author

Hmm, IDK then :(

One thing I missed in the code snippets you showed is the presence of mutexes. IDK how you are managing the shared objects in the code but I expected to see some locks at least in the code that changes _endThread. Is that supposed to be a lock-free code or something?

I can try to create a test application for you but it will take some days as I'm very busy nowadays :(

@the1schwartz
Copy link
Contributor

_endThread is of type std::atomic so there should be no need for mutexes as it can only be accesed by one thread at a time. Ok thanks. I will try to make a project myself in the meantime

@the1schwartz
Copy link
Contributor

I have tried to test the SDK using a DLL. I have just tested it in a simple windows desktop application made with C++. You can check it out here: https://drive.google.com/file/d/13O00rEboBO6oh4KNXQ9azz4xDKHNLi7y/view?usp=sharing

You probably need to check the path to the GameAnalytics DLL before building the project. When I tested it, it worked when I called the onQuit method when getting the close event for the application. Let me know if you still get the error using the provided test project.

@xdd12345
Copy link

xdd12345 commented Apr 1, 2019

HI,
I have the same problem with andresantacruz.The thread sometimes just don't die properly upon ExitProcess.

@the1schwartz
Copy link
Contributor

Do you also call onQuit?

@xdd12345
Copy link

xdd12345 commented Apr 2, 2019

Do you also call onQuit?
yes

@the1schwartz
Copy link
Contributor

Ok would you be able to send me a test project where this is reproducible as I can't seem to reproduce it myself

@xdd12345
Copy link

xdd12345 commented Apr 4, 2019

Ok would you be able to send me a test project where this is reproducible as I can't seem to reproduce it myself

Sure, I try it.would you give me a e-mail address?

@the1schwartz
Copy link
Contributor

Would can send it to [email protected]

@andresantacruz
Copy link
Author

@the1schwartz @xdd12345 Any news in the subject?

@xdd12345
Copy link

@the1schwartz @xdd12345 Any news in the subject?

Sry,I've been a bit busy lately, forget it,The project has not been sent yet. It will be sent in this week.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants