I’ve got a problem with a thread that I don’t understand.
The window tells the model to do start doing stuff.
The model starts a thread to do the stuff.
The thread does the stuff.
At the end of doing the stuff the thread signals the model that it is finished.
The model get’s a notification and does some cleanup tasks.
Unfortunately, I got some reports from customers that one of the cleanup tasks is started and then the thread goes on doing stuff. Since both doing stuff and the cleanup task involve the same database this results in a crash. I have never seen this problem myself and on good days I do debugging dozens of times.
Here is the last section of the session log from the customer:
2017-02-04, 11:51:41 emlxIterator.Constructor MailboxPath: iCloud:::some mailbox -> thread doing the stuff
2017-02-04, 11:51:41 emlxIterator.GetNumberOfObjects 1
2017-02-04, 11:51:41 ArchiveThread.Archive done -> thread is finished
2017-02-04, 11:51:41 MaxModel.DoDiagnose -> going back to model, starting clean up task
2017-02-04, 11:51:41 emlxIterator.Constructor MailboxPath: iCloud:::Familie -> thread is NOT finished
2017-02-04, 11:51:42 emlxIterator.GetNumberOfObjects 15 -> thread does stuff again, last information before crashing
Does anyone have an idea what could cause this? I’ve added some checks but these would only treat the symptom and not the root cause of the problem. There is only one thread at a time. Is there something fundamental that I have misunderstood when working with threads?
There is no semaphore controlling access. That’s a good idea but it would mean a large refactoring.
The root mechanism for the notification center is a simple observer pattern.
As far as I can see the thread isn’t started again. I should see this in both model and thread in the session logs. Also there is a progress window as a sheet so it’s impossible to start the thread without the previous one having finished.
I’ve seen “weird stuff” happen on single CPU cores with threads. <https://xojo.com/issue/30328> is an example describing high CPU usage. I’ve also seen event order change - my memory is fuzzy but I think that IPCSockets may behave strange as well on single core CPUs.
The customer’s computer has 24 GB with 4 cores and my app was the only app running.
@Michael Diehr: Your feedback case was just closed today! I’m not sure if it’s related to my problem. I think for now I’ll add some logging for CPU load.