Is it possible to safey call a procedure from within a thread? I am doing this but I have apparently random memory read errors (including at the ProcedureReturn point), which makes me think it might be a stack corruption problem, or at least a memory problem. On a computer with a large memory the problem will always occur though sometimes after many, many iterations. On an old computer with a small memory it will occur after only one or two. I haven't done anything completely stupid like foregetting to set ThreadSafe and I use LockMutex() to ensure that shared Global arrays are not accessed at the wrong time. I believe the code itself is robust. I cannot divorce the code from its program to post it, and in any case event the helpful PureBasic community might draw the line and running something for several hours before the error occurs!
I would appreciate any suggestions.
A Question about Procedures in Threads
-
CalamityJames
- User

- Posts: 82
- Joined: Sat Mar 13, 2010 4:50 pm
Re: A Question about Procedures in Threads
apart from globals, which it sounds like youve accommodated for already, the main problem arising from threads seems to be user interface updates. You should never do anything with UI from your worker threads, instead get them to tell the main thread to do the UI update, typically by PostEvent() [example]
-
CalamityJames
- User

- Posts: 82
- Joined: Sat Mar 13, 2010 4:50 pm
Re: A Question about Procedures in Threads
Thank you for your reply. I was running some gadget updates (SetGadgetText mostly), so I moved them to the main loop and I have been able to run many iterations on 3 different computers with no problems.
There is certainly no problem in principle going to a procedure in thread.
There is certainly no problem in principle going to a procedure in thread.
