Is it possible Multithreading in Powerbuilder 12.6? - powerbuilder

My question is about Can we do Multithreading in Powerbuilder 12.6?.
Thanks in Advance.

This is from a blog post I wrote a long time ago. Don't know if it's still accurate.
The way you do multithreading in PowerBuilder is to create an object
that contains the code you want to run in another thread. You then
create an instance of this object as a “shared object”. You also code
another object – the “interface object” and pass the shared object a
reference to it. You can then call functions on the shared object and
have them run in the other thread. The shared object communicates back
to the main thread via the interface object.

Yes, the SharedObject functions implement multi threading.


Android - One more “Accessing objects from a different thread”

I have a question about accessing objects on the main thread from another thread. There seems to be a lot of information about it online with techniques to do that but everything I found applies to accessing Views on the UI thread. It may be that all those techniques also apply for objects other than View but I would just like to make sure.
For my concrete example I have a custom BluetoothDeviceConection class I wrote and contains functions like connect, closeConnection, write and so on. So functions for managing a connection to a specific BluetoothDevice which is passed as a parameter to BluetoothDeviceConection's constructor. On my main thread I create three BluetoothDeviceConection objects for three devices. Now I want to connect to all three devices.
My idea is to send the BluetoothDeviceConection object of a device to a new thread, let it connect to that device and write data to it, thereby manipulating / modifying / accessing the passed BluetoothDeviceConection object. To make this thread safe everyBluetoothDeviceConection object would be created with the volatile keyword.
Is that the correct way to go?
I am doing a similar thing with a TimerTask in which I call an "outside" function marked as synchronized and everything works fine.
Thank you in advance for all your help.
No, volatile does not guarantee thread safeness by itself. volatile only tells compiler this value can be changed from multiple threads so it doesn't apply optimizations based on static code analysis. If you want it to be thread-safe, you need to use synchronized as you said for TimerTask or other methods (locks, semaphores, mutexes...) to make sure only one thread is accessing it at any given time.
I also suggest that instead of passing the BluetoothDeviceConection as a parameter to other classes, you wrap this object inside another class and write thread-safe methods for manipulating it.
Same as with TimerTask your own class will work fine

Similar Objective-C KVO in c++

I have this architetture:
I have a thread that continuously monitors the status of a shared variable.
I would like to develop a system similar to Objective-C KVO in c++ . In practice, I would like to notify to a thread02 the state change of a variable.
What do you call this kind of pattern?
What is the best way and easiest way to accomplish this?
I thought I can have a method of thread01 addObserver where you pass a function pointer, but I would like to be the thread02 executing the code of this function (when he'll be ready)
Do you have suggestions?
Some examples?
It's called the Observer pattern, and was originally described in the Design Patterns book. Examples in C++ exist e.g. at CodeProject.
To solve your threading problems, the callback function you supply to the observed object should act as a signal, which should wake the other thread and tell it to start its work. You could use a condition variable for this signal.

Pass XPCOM interface pointer cross the thread

I am new to develop Firefox extension with XPCOM. Currently I am using a background thread to do some work in XPCOM and need to pass a pointer of one XPCOM interface (eg nsIDomwindow) from main thread to that thread. But if use the pointer as the parameter in windows API fundtion Createthread and use it then, that will cause Firefox crash.
How to solve this issue? Is there any similar way to use CoMarshalInterThreadInterfaceInStream/CoGetInterfaceAndReleaseStream in MS com? Does the XPCOM only support single thread?
Look forward all your advice and sample code! Thanks in advance!
Many XPCOM objects aren't thread-safe, in particular any DOM objects can only be accessed from the main thread. To check whether an object is thread-safe you have to QueryInterface it to nsIClassInfo and check whether nsIClassInfo.flags contains nsIClassInfo.THREADSAFE flag. If it is then you can simply pass the interface pointer between threads.

Accessing the C++ COM dll from Webservice

I am using a COM dll from a web service.
The COM dll is added as reference. And I am declaring the object as static in Global.asax.
I am creating the COM object in the Application_Start.
I have to call the COM dll interface function in each request.
I am getting exceptions here as memory corruption.I could see the logs that it happens when simultaneous requests come up.
Please let me know what is the best way to do that. How to make it thread safe.?
Try creating a new instance in each request and not use application scope for the object.
If you are accessing it at application scope(eg through Application_Start) you will need to make sure it is safe for multithreading. I don't know how C++ dlls handle threading but you might be able to manage multithreading at the level.
For example To manage a simple application level counter the code is something like:
Application["SomeGlobalCounter"] =
(int)Application["SomeGlobalCounter"] + 1;
For more information you might want to see the MSDN page on Application State.
If the COM object is apartment threaded, COM provides the synchronization to enforce a single execution of a method per thread.
Generally, though, COM should be complaining of multiple threads trying to access an instance of an object using the same pointer shared across threads. Having a static variable holding a pointer to the object is probably a bad idea.
Once the COM object shared library is loaded somewhere (in-proc or out-of-proc) by creating an instance, creation of additional instances per thread should be fairly quick. That is, of course, dependent on what types of things that are being done during object construction.

Odd issue with std::map and thread safety

This isn't so much of a problem now as I've implemented my own collection but still a little curious on this one.
I've got a singleton which provides access to various common components, it holds instances of these components with thread ID's so each thread should (and does, I checked) have it's own instance of the component such as an Oracle database access library.
When running the system (which is a C++ library being called by a C# application) with multiple incoming requests everything seems to run fine for a while but then it crashes out with an AccessViolation exception. Stepping through the debugger the problem appears to be when one thread finishes and clears out it's session information (held in a std::map object) the session information held in a separate collection instance for the other thread also appears to be cleared out.
Is this something anyone else has encountered or knows about? I've tried having a look around but can't find anything about this kind of problem.
Standard C++ containers do not concern themselves with thread safety much. Your code sounds like it is modifying the map instance from two different threads or modifying the map in one thread and reading from it in another. That is obviously wrong. Use some locking primitives to synchronize the access between the threads.
If all you want is a separate object for each thread, you might want to take a look at boost::thread_specific_ptr.
How do you manage giving each thread its own session information? Somewhere under there you have classes managing the lifetimes of these objects, and this is where it appears to be going wrong.