I am posting this for John Hohnesee because he was having problems accessing the board. RD
After creating a application that is MODAL with over 7000 lines of code. I need to convert the application to thread safe.
This task will probably require a total rewrite of over 90 percent of the application. Could some one create a simple listing of the steps required to create thread save application. All of the samples that I have looked at have NOT been helpful just mind overload. Like the ant that looked at a large elephant with rape on his mind.
Creating Thread-Safe application
Creating Thread-Safe application
The eXpress train is coming - and it has more cars.
Re: Creating Thread-Safe application
John -
I'm not really sure what you mean by thread-safe (in your situation), but it seems unreasonable that you would need to change 90% of the code.
It is more likely that you will only need to touch 1% of your code.
First, you mentioned that your application is MODAL.
It is very simple to change your MODAL screens to Child Windows.
You need a PUBLIC pointer to your main window.
In your main program do this:
Then add this to the DCREAD GUI of your main window:
Next, to change your modal windows to Child Windows, make the following change to your DCREAD GUI of each window:
Finally, you need to call your windows in a new thread:
Each window that is started in a new thread must open and close all databases.
I would do this by writing a small wrapper function:
If you use LOCAL and PRIVATE variables in the code that creates your windows, then they will be already thread-safe.
If you use a lot of PUBLIC variables, then there is also a way to make them thread-safe by privatizing them as shown in the above function. This way they will be visible in each thread but if a value is changed in one thread it will not affect the value in another thread.
I'm not really sure what you mean by thread-safe (in your situation), but it seems unreasonable that you would need to change 90% of the code.
It is more likely that you will only need to touch 1% of your code.
First, you mentioned that your application is MODAL.
It is very simple to change your MODAL screens to Child Windows.
You need a PUBLIC pointer to your main window.
In your main program do this:
Code: Select all
PUBLIC MainWindow
Code: Select all
DCREAD GUI EVAL {|o|M->MainWindow}
Code: Select all
DCREAD GUI ;
;// MODAL SETAPPWINDOW ; <<<<< remove this
APPWINDOW M->MainWindow:drawingArea // <<<<<< add this
Code: Select all
DCMENUITEM 'Customers' ;
;// ACTION {||Customers()} ; <<<<< remove this
ACTION {|o|NewThread({||Customers()})} // <<<<<< add this
I would do this by writing a small wrapper function:
Code: Select all
FUNCTION NewThread( bAction )
LOCAL oThread := Thread():new()
Sleep(5)
oThread:start({||LaunchInNewThread(bAction)})
RETURN nil
* --------------
FUNCTION LaunchInNewThread( bAction )
PRIVATE myPublicFunction1 := M->myPublicFunction1
....
PRIVATE myPublicFunctionX := M->myPublicFunctionX
Eval(bAction)
dbCloseAll()
RETURN nil
If you use a lot of PUBLIC variables, then there is also a way to make them thread-safe by privatizing them as shown in the above function. This way they will be visible in each thread but if a value is changed in one thread it will not affect the value in another thread.
The eXpress train is coming - and it has more cars.
Re: Creating Thread-Safe application
This is the forth try. I am still getting the disconnect if anything is added such as sample code.
I thought you example was very good until I tried to use it, that is when I was lost. On your old board I uploaded one of the three applications that I need to convert, SFCW.PRG it is written in MODAL format. Tried to include it in the reply and got disconnected again.
I'm going to check with the BOSS [ ie: wife ] about attending the september event. If the BOSS allows us to go we will be coming in a 33 foot RV that we would need a place to plant it close enough to get to the event on foot since we do NOT have a tag along car. The last time we came our RV caught on fire just north of BAKER CA and we had to rent a car to get their.
We bought another RV at the VEGAS Camper World where our original RV was repaired. Then later declared a total loss by the insurance company. That was a very eventful trip.
I got it to post by SAVE then PREVIEW then SUBMIT. Am I missing something?
I thought you example was very good until I tried to use it, that is when I was lost. On your old board I uploaded one of the three applications that I need to convert, SFCW.PRG it is written in MODAL format. Tried to include it in the reply and got disconnected again.
I'm going to check with the BOSS [ ie: wife ] about attending the september event. If the BOSS allows us to go we will be coming in a 33 foot RV that we would need a place to plant it close enough to get to the event on foot since we do NOT have a tag along car. The last time we came our RV caught on fire just north of BAKER CA and we had to rent a car to get their.
We bought another RV at the VEGAS Camper World where our original RV was repaired. Then later declared a total loss by the insurance company. That was a very eventful trip.
I got it to post by SAVE then PREVIEW then SUBMIT. Am I missing something?
Re: Creating Thread-Safe application
I'm still trying to figure out why some board users cannot get their messages to post.
I have created a new FTP account to upload files if you have difficulty posting them here.
ftp://donnay-software.com
user: upload
pwd; upload
I have created a new FTP account to upload files if you have difficulty posting them here.
ftp://donnay-software.com
user: upload
pwd; upload
The eXpress train is coming - and it has more cars.
Re: Creating Thread-Safe application
I found within the source of provide by our leader the perfect example how to create full threded software in DCLIP1 the source for DBU has all the requirements for thread applications _DCDBU.PRG. Thanks Roger!