Hi All!
I have a question regarding launching multiple processes to utilize a multicore processor. I have built a shell property named “BETShell” which basically runs a BASH script with the argument “paradigm”. The argument is assigned based on contents of a listbox. The process is launched by a button with the action code below.
[code] Dim paradigm As String
Dim shl as BETShell
ReDim mCountShell(-1) // Clear any prior shells
for i as integer = 0 to Listbox2.ListCount-1
paradigm = Listbox2.cell(i,0)
shl = New BETShell(paradigm)
mCountShell.Append(shl)
shl.RunBET
next[/code]
My problem is that the process seem to launch sequentially rather than simultaneously and I am now at a loss for what the problem is. Any ideas? Thank you so much in advance!
[quote=174928:@Eric Hayden]Hi All!
I have a question regarding launching multiple processes to utilize a multicore processor. I have built a shell property named “BETShell” which basically runs a BASH script with the argument “paradigm”. The argument is assigned based on contents of a listbox. The process is launched by a button with the action code below.
[code] Dim paradigm As String
Dim shl as BETShell
ReDim mCountShell(-1) // Clear any prior shells
for i as integer = 0 to Listbox2.ListCount-1
paradigm = Listbox2.cell(i,0)
shl = New BETShell(paradigm)
mCountShell.Append(shl)
shl.RunBET
next[/code]
My problem is that the process seem to launch sequentially rather than simultaneously and I am now at a loss for what the problem is. Any ideas? Thank you so much in advance![/quote]
The usual way of creating a multicore mechanism is by launching a second Xojo app that will be running on another core. Then you can communicate between apps through IPC or some other mean.
Is your Shell asynchronous (Shell.Mode = 1)?
Thank you so much, Paul! I added that to the shell Constructor method and worked perfectly!
On a related note, is there an easy way to monitor for all shells (shl) to have completed before running a second script? i.e. after running i from 0 to 3 to run 4 instances of RunBET, monitoring for when all 4 instances have completed and then running a second type of script on the output data from RunBET?
I have considered various idea of YieldToNextThread, but am not coming up with a good solution of where this would go into the app which would keep the processes triggering simultaneously.
Shell has a Completed event handler. You could use that to create a way to know when each shell call has completed and thus know when they have all completed.
Problem solved! Thank you so much for your help! I basically added a global variable as a counter in the Shell.Completed event and triggered a timer to look for the global variable to reach the anticipated count that all shells had completed.
I am sure there is a prettier way, but it worked!
Thanks again!