English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 13 February 2019, 22:43   #1
dissident
Registered User

 
Join Date: Sep 2015
Location: Germany
Posts: 212
Question Task exit: Forbid() without Permit()

Hi,

actually I try to run some old OCS demos on an AGA machine. After these demos return to the WB, the system is frozen. I found out, that most of them use Forbid(), but returned without calling Permit().

Is there a way to detect, if a task exits, that it has not called Permit() after calling a Forbid() ?
dissident is offline  
Old 13 February 2019, 22:57   #2
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 44
Posts: 22,466
Forbid state should automatically go away when task that executed Forbid() is removed or if something forces task switch (like use of Wait()). Forbid (and Disable) is per-task state.
Toni Wilen is offline  
Old 13 February 2019, 23:01   #3
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 5,783
Forbid()
ReplyMsg(wbmsg)
return

is the normal ending of a program started from Workbench.

Forbid just sets a flag in the task structure. When the task ends, its Forbid status vanishes along with the task structure.

The above sequence of commands assures that the replied message can be received by Workbench only after the task has already ended.

This is not the cause of your freezes. Of course this part of the program should never be executed if it is run from the Shell. But even if you manage to call this from the Shell, it does not freeze the machine.
thomas is offline  
Old 13 February 2019, 23:05   #4
dissident
Registered User

 
Join Date: Sep 2015
Location: Germany
Posts: 212
Quote:
Originally Posted by Toni Wilen View Post
Forbid state should automatically go away when task that executed Forbid() is removed or if something forces task switch (like use of Wait()). Forbid (and Disable) is per-task state.
Yes, on pre OS2.0 systems, the Forbid state seems automatically to go away. But on OS 3.0, the WB doesn't freeze, if a Permit() is called right after the demo returned from its execution.
dissident is offline  
Old 13 February 2019, 23:10   #5
dissident
Registered User

 
Join Date: Sep 2015
Location: Germany
Posts: 212
Quote:
Originally Posted by thomas View Post
Forbid()
ReplyMsg(wbmsg)
return

is the normal ending of a program started from Workbench.

Forbid just sets a flag in the task structure. When the task ends, its Forbid status vanishes along with the task structure.

The above sequence of commands assures that the replied message can be received by Workbench only after the task has already ended.

This is not the cause of your freezes. Of course this part of the program should never be executed if it is run from the Shell. But even if you manage to call this from the Shell, it does not freeze the machine.
Maybe a misunderstanding. The demo is not called by an icon from WB. There is no WB-message that has to be replied. It is called from a shell window on the WB.
dissident is offline  
Old 13 February 2019, 23:16   #6
dissident
Registered User

 
Join Date: Sep 2015
Location: Germany
Posts: 212
Quote:
Originally Posted by thomas View Post
Forbid()

Forbid just sets a flag in the task structure. When the task ends, its Forbid status vanishes along with the task structure.
Maybe this could be a solution. Which flag is set in the task structure if Forbid was called ?
dissident is offline  
Old 14 February 2019, 10:26   #7
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 46
Posts: 3,405
Quote:
Originally Posted by dissident View Post
Maybe this could be a solution. Which flag is set in the task structure if Forbid was called ?
IIRC this is TDNestCnt. But it's a counter, not a mere flag (calls to Forbid must be matched by the same number of calls to Permit).
meynaf is offline  
Old 14 February 2019, 11:36   #8
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,209
Quote:
Originally Posted by dissident View Post
Yes, on pre OS2.0 systems, the Forbid state seems automatically to go away. But on OS 3.0, the WB doesn't freeze, if a Permit() is called right after the demo returned from its execution.

There must be another reason for the freeze, I just tried returning to the system without calling Permit() on my 3.1 machine and it worked without any problem.
Many old OCS demos trash memory and/or don't restore interrupt/hardware vectors correctly which can lead to problems such as system freezes.
StingRay is offline  
Old 14 February 2019, 14:12   #9
dissident
Registered User

 
Join Date: Sep 2015
Location: Germany
Posts: 212
Quote:
Originally Posted by meynaf View Post
IIRC this is TDNestCnt. But it's a counter, not a mere flag (calls to Forbid must be matched by the same number of calls to Permit).
Many thanks, meynaf. That's exactly what I need. I could check the counter value, and if it's not NULL, then there are one or more Permits missing. I guess Forbid() increments and Permit() decrements the counter by 1.
dissident is offline  
Old 14 February 2019, 14:19   #10
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 44
Posts: 22,466
Why do you still think permit have anything to do with this problem? It does not. It can't!
Toni Wilen is offline  
Old 14 February 2019, 14:23   #11
dissident
Registered User

 
Join Date: Sep 2015
Location: Germany
Posts: 212
Quote:
Originally Posted by StingRay View Post
There must be another reason for the freeze, I just tried returning to the system without calling Permit() on my 3.1 machine and it worked without any problem.
Many old OCS demos trash memory and/or don't restore interrupt/hardware vectors correctly which can lead to problems such as system freezes.
Generally you are right, StingRay. Most old OCS demos overwrite or trash memory or don't resore the hardware registers properly. But I make a copy of the whole CHIP memory (lower 1MB) before I execute the demo and restore it after the exit of the demo. Additionally I save the interrupts/DMACON/CIA registers and restore them also after the exit of the demo. In this case, using an additional Permit() was the solution. But it may be a random thing.

The demo is this one: http://www.pouet.net/prod.php?which=13856
dissident is offline  
Old 14 February 2019, 14:36   #12
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 44
Posts: 22,466
Was task structure or execbase also in stored/restored part of chip ram?
Toni Wilen is offline  
Old 14 February 2019, 14:37   #13
dissident
Registered User

 
Join Date: Sep 2015
Location: Germany
Posts: 212
Quote:
Originally Posted by Toni Wilen View Post
Why do you still think permit have anything to do with this problem? It does not. It can't!
Because I had a similar case in this startup code on OS3.x here:


Code:
 move.l    d0,-(sp) 
      
          tst.l    returnMsg        ; Is there a message? 
          beq.s    exitToDOS        ; if not, skip... 
      
          move.l    4.w,a6 
              jsr    _LVOForbid(a6)          ; note! No Permit needed! 
      
          move.l    returnMsg(pc),a1 
          jsr    _LVOReplyMsg(a6) 
      
      exitToDOS 
          move.l    (sp)+,d0        ; exit code 
          rts
A Permit() before rts is needed to prevent a frozen WB where you can't click on icons any more or they don't react any more.
dissident is offline  
Old 14 February 2019, 14:41   #14
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 44
Posts: 22,466
Thats standard official startup code. Every program that runs from WB uses it (like was already mentioned above).

You sure there was not some memory corruption or some other random problem that made task exit to hang? (=Forbid state didn't go away)
Toni Wilen is offline  
Old 14 February 2019, 14:53   #15
ross
Sum, ergo Cogito

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 48
Posts: 1,525
Quote:
Originally Posted by dissident View Post
A Permit() before rts is needed to prevent a frozen WB where you can't click on icons any more or they don't react any more.
Now you have intrigued me because I do not use Permit() before rts and it normally works.

If i'm not wrong it's mandatory to do the ReplyMsg() in Forbid() state and exit w/o a Permit() to prevent WB prematurely unloadseg the exe.
ross is offline  
Old 14 February 2019, 15:00   #16
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 46
Posts: 3,405
But does the task really exit ? If run from WB directly, it does. If run from some cli, then the cli is the current task and it does not get deleted after the program exits. Besides, the demo might leave the forbid/permit counter in any state...
meynaf is offline  
Old 14 February 2019, 17:30   #17
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,209
Quote:
Originally Posted by dissident View Post
Generally you are right, StingRay. Most old OCS demos overwrite or trash memory or don't resore the hardware registers properly. But I make a copy of the whole CHIP memory (lower 1MB) before I execute the demo and restore it after the exit of the demo. Additionally I save the interrupts/DMACON/CIA registers and restore them also after the exit of the demo. In this case, using an additional Permit() was the solution. But it may be a random thing.

The demo is this one: http://www.pouet.net/prod.php?which=13856

I have checked, the intro lacks blitter waits which are most likely the reason for the system freeze upon exit! Just saving hardware registers etc. is not enough to let the intro run properly on anything else than a plain 7 MHz Amiga, you need to add the blitter waits!
StingRay is offline  
Old 14 February 2019, 19:29   #18
dissident
Registered User

 
Join Date: Sep 2015
Location: Germany
Posts: 212
Quote:
Originally Posted by Toni Wilen View Post
Thats standard official startup code. Every program that runs from WB uses it (like was already mentioned above).
Yes, I use nearly the same code, but with an additional Permit. This method is confirmed by the Autodocs 1.3/2.0/3.5:

Quote:
Calls to Forbid() nest. In order to restore normal task rescheduling, the programmer must execute exactly one call to Permit() for every call to Forbid().
Quote:
Originally Posted by Toni Wilen View Post
You sure there was not some memory corruption or some other random problem that made task exit to hang? (=Forbid state didn't go away)
No, in that case, the demo worked properly and didn't corrupt memory areas. My tester on her A4000-060 told me, that without the Permit(), memory used by the task is not given back to the system.
dissident is offline  
Old 14 February 2019, 19:34   #19
dissident
Registered User

 
Join Date: Sep 2015
Location: Germany
Posts: 212
Quote:
Originally Posted by Toni Wilen View Post
Was task structure or execbase also in stored/restored part of chip ram?
The main program which loads and executes the demo is in FAST memory, so I guess the task structure, too. The execbase is in lower CHIP memory.
dissident is offline  
Old 14 February 2019, 20:00   #20
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 44
Posts: 22,466
Quote:
Originally Posted by dissident View Post
Yes, I use nearly the same code, but with an additional Permit. This method is confirmed by the Autodocs 1.3/2.0/3.5:
Missing Permit() is REQUIRED when program was started from WB. Check Workbench chapter in RKRM.

When WB gets the message back, it will UnloadSeg() and free all memory. If task switching is enabled, program may get unloaded before following instruction(s) are executed.
Toni Wilen is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exit winuae? magoomba New to Emulation or Amiga scene 7 26 October 2018 23:50
pc task 4.4:) 8bitbob support.Apps 5 25 October 2016 23:01
Startup Code (from Icon ) - Forbid function Asman Coders. System 2 04 January 2014 11:45
Cannot exit from Some games @UAE project.WHDLoad 13 19 November 2008 14:28
OS 3.9 can't exit and some more problems Tea support.WinUAE 1 09 July 2003 13:51

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:35.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.08999 seconds with 13 queries