-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmultiple_instances.prg
More file actions
46 lines (39 loc) · 1.13 KB
/
Copy pathmultiple_instances.prg
File metadata and controls
46 lines (39 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
* Multiple instances
Set Path To "..;EXAMPLES" Additive
Wait "Starting workers..." Window Nowait
* Default instance uses out-of-process workers
Local Parallel as Parallel
Parallel = NewObject("Parallel", "ParallelFox.vcx")
Parallel.StartWorkers(FullPath("multiple_instances.prg"))
* Second instance uses in-process workers
* Since in the same prg, Parallel reference must be a different name
Local Parallel2 as Parallel
Parallel2 = NewObject("Parallel", "ParallelFox.vcx")
* Set instance name before other settings and starting workers
Parallel2.SetInstance("INPROCESS")
Parallel2.SetMultiThreaded(.t.)
Parallel2.StartWorkers(FullPath("multiple_instances.prg"))
* Do work in both instances simultaneously
Wait "Running code in parallel..." Window Nowait
Parallel.Do("RunUnits",,,10)
Parallel2.Do("RunUnits",,,10)
Parallel.Wait()
Parallel2.Wait()
Parallel.StopWorkers()
Parallel2.StopWorkers()
Wait clear
MessageBox("Code Complete.")
* Run specified units of work
Procedure RunUnits
Lparameters lnUnits
Local i
For i = 1 to lnUnits
SimulateWork()
EndFor
EndProc
Procedure SimulateWork
Local i
For i = 1 to 10000000
* Peg CPU
EndFor
EndProc