1. Narayana Bhat
  2. PowerBuilder
  3. Saturday, 11 November 2017 07:04 AM UTC

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

Accepted Answer
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 13 November 2017 14:09 PM UTC
  2. PowerBuilder
  3. # Permalink

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.

Comment
  1. Narayana Bhat
  2. Tuesday, 14 November 2017 04:38 AM UTC
Dear Roland,



Thanks, I will go through that



Narayana

  1. Helpful
There are no comments made yet.
Marco Meoni Accepted Answer Pending Moderation
  1. Sunday, 12 November 2017 19:26 PM UTC
  2. PowerBuilder
  3. # 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

Comment
  1. Narayana Bhat
  2. Monday, 13 November 2017 05:05 AM UTC
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

  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Sunday, 12 November 2017 02:32 AM UTC
  2. PowerBuilder
  3. # 2

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)

Comment
There are no comments made yet.
Marco Meoni Accepted Answer Pending Moderation
  1. Saturday, 11 November 2017 08:26 AM UTC
  2. PowerBuilder
  3. # 3

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

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.