|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
DanRRight
Joined: 10 Mar 2008 Posts: 2819 Location: South Pole, Antarctica
|
Posted: Fri Sep 18, 2009 8:21 pm Post subject: Make changes to this run-pause-stop code |
|
|
Clearwin+ is nice piece of software.
With 1-2 exclusions . And these couple seemingly easy tasks would cost you a couple months of trying of every possible variant.
Do you want a piece of weekend hell with Clearwin+? What needed is clear from the source and exe file.
Make minimal changes for this code so it will start run, pause, continue or stop flawlessly.
(You may use permit_another_callback@ if you will make it work reliably but i never succeeded. This prototype will be part of large code with many opening and closing windows. As soon as you've do one of these windows closed non-properly for example by clicking on its X in the window corner or before run inside the window is complete - the whole large code with all its millions windows will stop working and we will return to what you will see below)
You can try to make the same functionality (but it must be as intuitive as this example below) with any other Windows GUI builder in Fortran. I have Winteracter but I've never tried. There exist other GUI builders. Interesting if they work.
I know couple solutions, but they are not intuitive and are not very short. And they require opening additional unneeded window. Every time when i start new project in a year or three i forget how i came there while extracting them out of large codes takes hours. So i return to the same old bad song and fail again for hours. Hope there exist solution to make the code work as simple and straightforward as it is written below
Code: |
use clrwin
common kRun
integer longrun
external longrun
ioLUN = 10
kRun=1
i=WINIO@('%ww%bg[btnface]&')
i=WINIO@('%mn[File[Exit]]&','exit')
i=WINIO@('%ac[esc]&','exit')
i=WINIO@('%^tt[Start]&','+','set',kRun,1,LongRun)
i=WINIO@('%^tt[Pause]&','set',kRun,0)
i=WINIO@('%^tt[Continue]&','set',kRun,1)
i=WINIO@('%^tt[Stop]%ff&','set',kRun,-1)
i=WINIO@('%`bg%60.4cw[hscroll,vscroll]', rgb@(214,214,255), ioLUN)
end
!-------
integer function LongRun()
use clrwin
common kRun
k=0
do while (kRun==0.or.kRun==1)
dowhile (kRun==0) ! pause/continue
if(kRun==-1) goto 1 ! stop
call sleep1@(0.5)
write(10,*)'Pause, kRun=', krun
enddo
k=k+1
write(10,*) k, ' kRun=',kRun
if(kRun==-1) goto 1
enddo
1 LongRun= 1
end function LongRun |
Last edited by DanRRight on Sat Sep 19, 2009 7:53 pm; edited 3 times in total |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7928 Location: Salford, UK
|
Posted: Sat Sep 19, 2009 8:28 am Post subject: |
|
|
I do not have a compiler to hand at the moment but here are some things to consider.
The problem and key concerns the call to sleep1@. The question is, how can you release the processor to handle mouse events etc whilst doing some number crunching say. One approach is to call temporary_yield@ but this is not always ideal. permit_another_callback@ is also sometimes relevant. In the worst case you may need to spawn another thread or another process. |
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2819 Location: South Pole, Antarctica
|
Posted: Sat Sep 19, 2009 6:57 pm Post subject: |
|
|
I've tried them many times in production codes, they do not work reliably.
Yes, temporally_yield@ helps if you use sleep1@ (and is always has to be used before sleep1@). In this example it does not matter since write is there.
I wrote that sometimes it looks like approach works, but adding smallest thing to it and it breaks. That was with permit_another_callback@. It also has such bad property that you will need to add it to all other opening windows in the code which makes approach cumbersome (i have many 1000th of different windows sometimes) and make sure they did not grabbed this "permitted another calback".
And multithreaded run-pause-stop prototype looks like works, see here http://forums.silverfrost.com/viewtopic.php?t=1149&highlight=
but you add just couple new lines to it like read_url@ and it permanently crashes
So i prefer to see exactly such clear simplest intuitive example above working, this is one of the most important functionalities Clearwin needs to address.
By the way how permit another callback works? Is there any danger to call it permanently many (who knows, may be millions?) times? In other words is this permanent call of permit in the do loop legitimate ? This code so far works
Code: | use clrwin
common kRun, kFinishedStatus
integer longrun
external longrun
ioLUN = 10
kRun=1
kFinishedStatus=1
i=WINIO@('%ww%bg[btnface]&')
i=WINIO@('%mn[File[Exit]]&','exit')
i=WINIO@('%ac[esc]&','exit')
i=WINIO@('%~^tt[Start]&',kFinishedStatus,'+','set',kRun,1,LongRun)
i=WINIO@('%^tt[Pause]&','set',kRun,0)
i=WINIO@('%^tt[Continue]&','set',kRun,1)
i=WINIO@('%^tt[Stop]%ff&','set',kRun,-1)
i=WINIO@('%`bg%60.4cw[hscroll,vscroll]', rgb@(214,214,255), ioLUN)
end
!-------
integer function LongRun()
use clrwin
common kRun, kFinishedStatus
CALL PERMIT_ANOTHER_callback@()
if(kFinishedStatus.eq.0) goto 2
kFinishedStatus = 0
k=0
write(10,*)'Pause, kRun=', krun
do while (kRun==0.or.kRun==1)
dowhile (kRun==0) ! pause/continue
if(kRun==-1) goto 1 ! stop
call temporary_yield@
call sleep1@(0.25)
call sound@(9933,1)
CALL PERMIT_ANOTHER_callback@()
write(10,*)'Pause, kRun=', krun
enddo
k=k+1
CALL PERMIT_ANOTHER_callback@()
write(10,*) k, ' kRun=',kRun
if(kRun==-1) goto 1
enddo
1 write(10,*)'END kRun=', krun
kFinishedStatus=1
2 LongRun= 1
end function LongRun
|
|
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2819 Location: South Pole, Antarctica
|
Posted: Thu Oct 01, 2009 10:47 pm Post subject: |
|
|
Well, after 2 weeks of permanent testing the code filled with the flood of "permit another callbacks" (like 10 times per second) seems works fine. Starting to extend it, adding buttons, controls and other windows and see what will happen |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|