1. Christopher Craft
  2. PowerBuilder
  3. Tuesday, 16 May 2017 23:21 PM UTC

PB 12.5.1

I know that global variables are not shared across threaded objects but is it safe to create a new instance and set the global variable to that in the threaded object (ie. SQLCA)? My situation is this - I create multiple threads (sharedobjects) that connect to the database to do certain work. Any newly created thread will create there own transaction object and connect to the database. I am now enhancing this so the threads can process other NVO service objects but those objects use the global transaction object to do their work. I started to go down the path of creating an instance transaction variable for these service objects and then I just set it to the threads transaction object. This works fine until these service objects use other service objects and then it starts to get a little messy. If it is supported to set the global transaction object in the thread then all my other NVO service objects will just work without change.

Thanks for your thoughts,

Chris Craft

Accepted Answer
Chris Pollach Accepted Answer Pending Moderation
  1. Wednesday, 17 May 2017 14:09 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Chris;

  There are no issues with using global variables in a sub-thread. While it is restricted in the sub-thread-itself, there is no rule that says you cannot pass in any reference addresses to the sub-thread that you need from the main thread. So just have the main task pass the address of SQLCA to the sub-thread as required.

Check out this example .. click here

HTH

Regards ... Chris

Comment
  1. Christopher Craft
  2. Wednesday, 17 May 2017 17:08 PM UTC
That is what I wanted to hear! Everything is working perfectly by setting these variables in the thread.  I just didn't want to be using them if it was not a supported "feature".



Thanks Chris!

  1. Helpful
There are no comments made yet.


There are replies in this question but you are not allowed to view the replies from this question.