This is probably trivial and I'll look at it tomorrow, slap my forehead and wonder why I needed to go on the forum to ask. Still, brain mush time today so,
I have a program that runs on a variety of uni and multi processor and uni and multi core machines "laying around" here. To save having to run multiple copies of the program on each machine that supports it, I've re-written it to use threads as the task splits nicely in a number (44 to be precise) of parallel tasks however the 44 tasks aren't of equal length.
If I just do
it works and the OS sorts out all the thread stuff but it seems to spend a lot more time doing the work so I presume it's spending it's life context switching the threads instead of working.
I tried messing around with SLEEP but then the box just sits around sleeping.
I can enumerate the CPUs/cores with
so I could just launch cp& worker threads at a time by doing something like using a STEP in the loop but that's not smart enough to spot when a thread's done and spawn the next one as they may not finish in sequence.
The logic of what I need/want to do is launch cp& worker threads and as any one finishes, spawn the next so that cp& worker threads are running.
Note the loop counter (ie 1 to 44) is a parameter each thread needs to know which part of the overall task it's doing.
Or, launch all 44 threads (memory resource isn't an issue), sleep 44-cp& of them and just wake one up every time one completes until they're all done.
Currently, once spawned, the following code
lifted almost verbatim from the samples waits for all 44 to finish and also monitors for the user (me
) quitting the program, before continuing.
I have a program that runs on a variety of uni and multi processor and uni and multi core machines "laying around" here. To save having to run multiple copies of the program on each machine that supports it, I've re-written it to use threads as the task splits nicely in a number (44 to be precise) of parallel tasks however the 44 tasks aren't of equal length.
If I just do
Code:
FOR f&=1 TO 44 THREAD CREATE MyThread(f) TO idThread(f) NEXT
I tried messing around with SLEEP but then the box just sits around sleeping.
I can enumerate the CPUs/cores with
Code:
LOCAL SI AS SYSTEM_INFO GetSystemInfo SI cp&=SI.dwNumberOfProcessors
The logic of what I need/want to do is launch cp& worker threads and as any one finishes, spawn the next so that cp& worker threads are running.
Note the loop counter (ie 1 to 44) is a parameter each thread needs to know which part of the overall task it's doing.
Or, launch all 44 threads (memory resource isn't an issue), sleep 44-cp& of them and just wake one up every time one completes until they're all done.
Currently, once spawned, the following code
Code:
DO SLEEP 5000 FOR f&=1 TO 44 THREAD STATUS idThread(f&) TO e& IF e&<>-1 THEN EXIT FOR NEXT i$=INKEY$ IF i$="q" THEN EXIT FUNCTION LOOP WHILE e&<>-1

Comment