1. Gregory Rusak
  2. PowerBuilder
  3. Friday, 1 December 2023 21:54 PM UTC

Hello,

We have a number of processes in our application (PowerBuilder 2021 build 1288) that we have multi-threaded where the callback function on the callback nvo returns the thread id as a LONG, a status code message as a STRING and the raw JSON as a STRING.

We wanted to move our JSON parsing to do the work within our thread, where the JSON STRING is parsed into a datastore, and then the datastore is passed back to the main application thread through the callback nvo function.

However, this approach does not work (just hangs) and we're wondering why you can't return a datastore back to the main thread, but you can return the JSON STRING or alternatively as we have found you can return the datastore as a BLOB using SetFullState and GetFullState.

I'm sure there must be a valid reason for this, but does seem odd to me. Also, there are no global functions or such in the dataobject; it is a simple external data source with a key, value and node columns. Here's an example of the callback functions:

Ideas and feedback are welcomed and appreciated in advance.

Thanks,

Greg

 

Accepted Answer
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 1 December 2023 22:52 PM UTC
  2. PowerBuilder
  3. # Permalink
For "Standard" data types that would be fine. But for object references, that should always be as a Pointer (by REF).
Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 1 December 2023 22:21 PM UTC
  2. PowerBuilder
  3. # 1

Hi Greg;

  Are you passing the DS back to the main thread as a reference argument?

Regards .. Chris

Comment
  1. Gregory Rusak
  2. Friday, 1 December 2023 22:34 PM UTC
In all three cases, the data is passed back by "value".
  1. Helpful
There are no comments made yet.
Gregory Rusak Accepted Answer Pending Moderation
  1. Friday, 1 December 2023 22:32 PM UTC
  2. PowerBuilder
  3. # 2

Hi Chris,

That would be a "No".

Regards,

Greg

Comment
  1. Gregory Rusak
  2. Friday, 1 December 2023 22:40 PM UTC
Curious, why then does a copy of a STRING or a BLOB work, whereas a datastore doesn't? I can try that, but doesn't the reference go out of scope once the thread is destroyed?
  1. Helpful
  1. Gregory Rusak
  2. Friday, 1 December 2023 22:41 PM UTC
... or make a copy of the "referenced" datastore before destroying the thread? I think that may work.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Friday, 1 December 2023 23:42 PM UTC
Yes, allocating the DS in the calling NVUO and then passing that in to the Sub-Thread should work nicely. ;-)

  1. Helpful
There are no comments made yet.
Gregory Rusak Accepted Answer Pending Moderation
  1. Friday, 1 December 2023 22:51 PM UTC
  2. PowerBuilder
  3. # 3

Hello Chris,

Thanks for the quick response.

I think we'll stay with the serialization of the datastore into a BLOB and pass that back by value.

Very helpful to know that objects must be passed by reference. Something learned.

Appreciated.

Kind Regards,

Greg

Comment
  1. Chris Pollach @Appeon
  2. Friday, 1 December 2023 23:42 PM UTC
That would certainly be the "safe" approach as a BLOB is a standard data type. ;-)
  1. Helpful
  1. Benjamin Gaesslein
  2. Monday, 4 December 2023 08:05 AM UTC
I'd suggest passing the blob by reference, too. Saves you a lot of memory.
  1. Helpful 1
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.