- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
I have a deadlock problem in my QuickWin Application. My Main Program runs in a do loop:
bCalculationLeft = .false.
do while(bCalculation)
... calling a lot of subroutines and functions ...
end do
bCalculationLeft = .true.
In the menu I have a entry for opening new projects. When the user clicks on that entry, an external subroutine is called and a File opening window will be openend. Meanwhile in the background, the calculation is still running. When the user finally opens a file, the following will be done:
bCalculation = .false.
do while(.not.bCalculationLeft)
call sleepQQ(100)
end do
call loadProject(filename)
Because the loadProject subroutine changes the variables, that are used in the do while(bCalculation) loop, I have to wait until this loop was exited because of Run-Time errors. So I programmend the do while(.not.bCalculationLeft) loop to avoid this.
In 90% this works. In the other 10% the program justs hangs and does not respond anymore.
Is there something I miss or dont do right?
Thanks in advance,
Markus
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
I have a deadlock problem in my QuickWin Application. My Main Program runs in a do loop:
bCalculationLeft = .false.
do while(bCalculation)
... calling a lot of subroutines and functions ...
end do
bCalculationLeft = .true.
In the menu I have a entry for opening new projects. When the user clicks on that entry, an external subroutine is called and a File opening window will be openend. Meanwhile in the background, the calculation is still running. When the user finally opens a file, the following will be done:
bCalculation = .false.
do while(.not.bCalculationLeft)
call sleepQQ(100)
end do
call loadProject(filename)
Because the loadProject subroutine changes the variables, that are used in the do while(bCalculation) loop, I have to wait until this loop was exited because of Run-Time errors. So I programmend the do while(.not.bCalculationLeft) loop to avoid this.
In 90% this works. In the other 10% the program justs hangs and does not respond anymore.
Is there something I miss or dont do right?
Thanks in advance,
Markus
If not, then once you enter the loop with the Sleep command, then the conditionin the loop can never be changed, and so the loop cannot ever exit.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If not, then once you enter the loop with the Sleep command, then the conditionin the loop can never be changed, and so the loop cannot ever exit.
David
I havent created any process threads.
I just use this:
ret=InsertMenuQQ(1,1,$MenuEnabled,'Open Project'C,OpenProjectDialog)
and in the subroutine OpenProjectDialog I have the do while(.not.bCalculationLeft) loop. AFAIK the subroutine OpenProjectDialog is being started as a sperate thread. Because the calculation is still running in the background I think that it is that way. Or is it just because the open dialog is a modeless dialog?
Hm, I just checked with Spy++. The main window has the same thread as the open file dialog...
So, I have to call the subroutine OpenProjectDialog as a seperate thread to archive my goal? How can I do this? Do I have to use CreateThread and ExtThread for this or is there another way?
Markus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I havent created any process threads.
I just use this:
ret=InsertMenuQQ(1,1,$MenuEnabled,'Open Project'C,OpenProjectDialog)
and in the subroutine OpenProjectDialog I have the do while(.not.bCalculationLeft) loop. AFAIK the subroutine OpenProjectDialog is being started as a sperate thread. Because the calculation is still running in the background I think that it is that way. Or is it just because the open dialog is a modeless dialog?
Hm, I just checked with Spy++. The main window has the same thread as the open file dialog...
So, I have to call the subroutine OpenProjectDialog as a seperate thread to archive my goal? How can I do this? Do I have to use CreateThread and ExtThread for this or is there another way?
Markus
You haven't created any threads, but QuickWin has. The "primary" thread runs the message loop, i.e. all the windows, menus, and everything from the callbacks. The "secondary" thread runs the PROGRAM; generally, it is not intended for UI windows, but you may execute a modal dialog from it (because it rides on its own message loop) but not a modeless one.
Now, I admit I didn't exactly understand who waits for whom and what causes the deadlock... however...
You can use global logical variables if you can ensure no deadlock, but you should generally not rely on SLEEPs "for long enough time" (except that sleep(0) yields control to another thread). For more reliable synchronization, you can use CreateEvent/RaiseEvent/WaitForSingleObject APIs. (Note, however, that WaitForSingleObject will halt the thread, and it's unpleasant for the GUI/primary thread).

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page