Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threads
#1
Hi Gintaras,
I will occasionally see this in the output:

Quote:Warning: There are 200 threads. QM may fail to create more threads and stop working.
Warning: There are 201 threads. QM may fail to create more threads and stop working.
Warning: There are 202 threads. QM may fail to create more threads and stop working.
Warning: There are 203 threads. QM may fail to create more threads and stop working.
Warning: There are 204 threads. QM may fail to create more threads and stop working.
Warning: There are 205 threads. QM may fail to create more threads and stop working.
Warning: There are 206 threads. QM may fail to create more threads and stop working.
Warning: There are 207 threads. QM may fail to create more threads and stop working.
Warning: There are 208 threads. QM may fail to create more threads and stop working.
Warning: There are 209 threads. QM may fail to create more threads and stop working.
Warning: There are 210 threads. QM may fail to create more threads and stop working.
Warning: There are 211 threads. QM may fail to create more threads and stop working.
Warning: There are 212 threads. QM may fail to create more threads and stop working.
Warning: There are 213 threads. QM may fail to create more threads and stop working.
Warning: There are 214 threads. QM may fail to create more threads and stop working.
Warning: There are 215 threads. QM may fail to create more threads and stop working.
Warning: There are 216 threads. QM may fail to create more threads and stop working.
Warning: There are 217 threads. QM may fail to create more threads and stop working.


It doesn't go on forever or crash, so I think whatever is creating the multiple threads stops. But I can't see how to find the function that is doing this. Is there a good strategy (when there are multiple candidates?).
I think it is something triggering an update of a dialog web page but I am not sure.
Thanks for any thoughts,
S
#2
In "Running items" pane you can see what function it is. What is its trigger?
#3
still having this problem...can't seem to figure it out...it is intermittent and sometimes will go up to 300 or 400 threads before just stopping on its own without crashing QM or the QM-generated exe. I have a lot of various WM_TIMER functions being called from a dialog (mac "func name"). But these all close quickly and don't even stay open long enough to show in running threads window. I have checked off "Run single instance only" in all all the functions that I see in the running threads so shouldn't generate these large numbers. And only one instance of each one is in the running threads window. If there were three hundred or so threads running, how come these don't show up in running threads window. Sorry for rambling post. Not sure how to track down the crazy multiplying thread! Any ideas on how to investigate? Maybe place out statements in all macros?
S
ps Happy Holidays Gintaras!
#4
Right click in the "Running items" pane and check "+hidden".

Also, QM closes handles of ended threads after several seconds, not immediately, because macros may need them (eg used with wait H). These threads also are counted, therefore you may see these warnings when starting/ending threads very frequently.

Try to reduce the number/frequency of threads. Replace mac "function_name" with function_name where possible. Or use single thread running all the time and somehow notify it to do the work when need. Starting a thread is not very cheap.
#5
Example. Dialog starts other thread, and on timer notifies it to do some work.
Function dialog_and_thread
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

if(!ShowDialog("dialog_and_thread" &dialog_and_thread)) ret

;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040000 "" "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,SetTimer hDlg 1 500 0
,int- t_iid=qmitem("and_thread")
,
,case WM_TIMER
,sel wParam
,,case 1
,,;mac "and_thread" ;;bad
,,
,,;good
,,__Handle+ g_andThreadEvent; if(!g_andThreadEvent) g_andThreadEvent=CreateEvent(0 0 0 0)
,,SetEvent g_andThreadEvent
,,if(!IsThreadRunning(+t_iid)) mac("and_thread")
,,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
Function and_thread
Code:
Copy      Help
if(getopt(nthreads)>1) ret
rep
,wait 0 H g_andThreadEvent
,out "and_thread works"
#6
Thank you Gintaras. Very very informative post and I will adjust my dialogs and associated macros/functions right away.
I am wondering how to quantify or get a feel for the performance hit of opening and closing threads. I scan the CPU performance and I think I am hovering around 0-1% - sometimes I will have things with complicated Find acc statements that will make it go higher but then I instead usually set things up to look for something easier to keep the CPU performance % low. How else is the "cost" of opening threads assessed - will I be seeing a need to reboot more often for optimal performance, more frequent crashes of QM-created exe's or non-QM related applications or processes, intermittent pauses, lockups....?
Thanks so much again!!!
S
#7
Quote: will I be seeing a need to reboot more often for optimal performance, more frequent crashes of QM-created exe's or non-QM related applications or processes, intermittent pauses, lockups....?
No.
Each thread reserves >1MB of memory address space of current process, although most threads use maybe 20-100KB of physical memory. The address space is limited, therefore the number of possible threads in current process is limited.
To compare speed:
Macro Macro2212
Code:
Copy      Help
PerfFirst
rep 100
,func0
PerfNext
rep 100
,;mac "func0" ;;this is fast because does not wait until thread created (the main QM thread does it, not this thread)
,_i=mac("func0") ;;waits until thread created, but does not wait until it ends
,;wait 0 H mac("func0") ;;waits until thread created and ends
PerfNext
PerfOut
Function func0
Code:
Copy      Help
;empty
#8
thanks!!! S
#9
To reproduce the warnings.
Macro Macro2212
Code:
Copy      Help
out
;Because of wait, there is 1 thread of "func1" at a time.
;But you'll see the warning anyway, because QM will close thread handless after some time.
rep 205
,wait 0 H mac("func0") ;;waits until thread created and ends
2
;No warning, all handles already closed.
mac("func0")
#10
that reproduces it exactly....Thanks for the taking the time to explain and illustrate the inner workings of programming/QM!
Stuart


Forum Jump:


Users browsing this thread: 1 Guest(s)