Multi Threading in PowerBuilder

1
-1
-1

Hi All,

Is it possible use multi threading in powerbuilder application?

We have a requirement that 1 lakh payroll record to be processed in limited time period so thinking to use multi threading where process can be placed parallel by dividing the volumes

Narayana Bhat

Question Tags: 

Answers

Marco Meoni answered Multi Threading in PowerBuilder

1
0
-1

Hi Narayana,

yes, you can leverage Shared Objects for that.
- SharedObjectRegister allows to instantiate a PB NVO as a "shared" object (an object running in a different thread)
- SharedObjectGet —gets a reference variable to the shared object

—A method in the new thread can be executed asynchronously if called with POST, e.g. inv_shared.POST of_myLongProcess(...). Finally, if you need to send the results from the shared object to the main thread (usually the application), you must have the shared object to execute an "interface" object's method (a.k.a. "callback") and pass results.

In a nutshell (please refer to PB help):

1) SharedObjectRegister("nvo_shared", "share1”)
2) SharedObjectGet("share1", nv_thread1)
3) nv_thread1.POST myLongProcess(arg1, … , nv_callback)
4) nv_callback.POST display_values(val1, …)

Cheers,

Marco

Roland Smith answered Multi Threading in PowerBuilder

1
0
-1

The background threads will be running on the same logical cpu as the main thread so I'm not sure if you will see real improvement in performance.

You might be able to use the function SetThreadAffinityMask to assign each thread to a different cpu. I have not tried this so I'm not sure it will work.

I have used SetProcessAffinityMask to assign the entire process.

 
Function boolean SetProcessAffinityMask ( long hProcess, ulong lpProcessAffinityMask ) Library "kernel32.dll"

Long ll_hProcess = -1  // -1 = current process
ULong lul_paMask

// calculate the bit mask - note that cpu id starts at zero
lul_paMask = 2 ^ai_cpu

Return SetProcessAffinityMask(ll_hProcess, lul_paMask)

Marco Meoni answered Multi Threading in PowerBuilder

1
0
-1

Hi Roland,

Each shared obj will be running in its own thread and will be calling methods asynchronously.

The main advantage is that long scripts will not freeze the main GUI thread.

Changing affinity pragmatically may certainly be of help under heavy load, but in general I would let the O.S. to take care of CPU pinning by itself.

Cheers,

Marco

Narayana Bhat's picture

Dear Marco,

Thanks for the reply, is it possible to get sample script ? it will be highly appreciable if you can share sample script

Narayana

Roland Smith answered Multi Threading in PowerBuilder

1
0
-1

I have an example of using shared objects in this program:

http://www.topwizprogramming.com/freecode_winsock.html

The UDP Listen tab uses the shared object. I am using the Send function to trigger events on the main window.

Narayana Bhat's picture

Dear Roland,

Thanks, I will go through that

Narayana