Device file not closing on close command 
Author Message
 Device file not closing on close command

Hi,

the program below controls a task handeling a serial device. The task
opens the device file, and 5 secs later the device file should be
closed. When running the program below, the device is opened, but when
the time comes to close the device the task just blocks on the
closecommand. If I open and close the device from the main procedure it
just works fine. The device is connected to a GPS receiver which is
constantly sending data. I am using gnat 3.13 onlinux (2.1.18) and linux
native threads.

Why does the task block(is it because there is still unread data in the
device -- but why would it work then if I open and close the device from
the main procedure rather than from the task ?) ? How can I make the
task close the file right away ?

Thank you,

Tilman                  

================== main =====================
with Text_IO;use Text_IO;
with Device;use Device;

procedure access_dev is
   TtyS2:   DevTask;
   In_Stream: File_Type;
begin
   TtyS2.Open("/dev/ttyS2");
   delay(5.0);
   Put_Line("waited for 5 secs");
   TtyS2.Close;

end access_dev;

=============== package specification ==============
package Device is
   task type DevTask is
      entry Open(Dev:String);
      entry Close;
      entry Quit;
   end DevTask;
end Device;
============== package body =======================
with Text_Io;use Text_Io;
with Device; use Device;
package body Device is
      task body DevTask is
         Exit_Flag: Boolean := False;
         In_Stream: File_Type;
         Buf:       String(1..82);
         Noc:       Integer := 0;
      begin
         while (Exit_Flag = False) loop        
            select
               accept Open(Dev:String) do
                  Put_Line("Openening Device " & Dev );
                  Open(In_Stream,IN_FILE, "/dev/ttyS2");
                  Put_Line("Device opened");
               end Open;
            or
               accept Close do
                  --if (Is_Open(In_Stream)) then
                     Put_Line("Closing Device");
                     Close(In_Stream);
                     Put_Line("Device closed");
            --      end if;
               end Close;
            or
               accept Quit do
                  Exit_Flag := True;
               end Quit;
            or
               delay(0.0);
--               if (Is_Open(In_Stream)) then
                   Get_Line(In_Stream,Buf,Noc);
                   Put_Line(Buf(1..Noc));
--               end if;
            end select;
         end loop;
       Put_line("Task terminated");
      end DevTask;
end Device;



Tue, 11 Nov 2003 02:39:00 GMT  
 Device file not closing on close command
Procedure access_dev is the master of task TtyS2.  Since you never told
TtyS2 to quit it is still running, so access_dev can not complete.  Call the
"quit" entry after you call the "close" entry.

---
Patrick Rogers                       Consulting and Training in:
http://www.classwide.com          Real-Time/OO Languages

(281)648-3165                                 Software Fault Tolerance


Quote:
> Hi,

> the program below controls a task handeling a serial device. The task
> opens the device file, and 5 secs later the device file should be
> closed. When running the program below, the device is opened, but when
> the time comes to close the device the task just blocks on the
> closecommand. If I open and close the device from the main procedure it
> just works fine. The device is connected to a GPS receiver which is
> constantly sending data. I am using gnat 3.13 onlinux (2.1.18) and linux
> native threads.

> Why does the task block(is it because there is still unread data in the
> device -- but why would it work then if I open and close the device from
> the main procedure rather than from the task ?) ? How can I make the
> task close the file right away ?

> Thank you,

> Tilman

> ================== main =====================
> with Text_IO;use Text_IO;
> with Device;use Device;

> procedure access_dev is
>    TtyS2:   DevTask;
>    In_Stream: File_Type;
> begin
>    TtyS2.Open("/dev/ttyS2");
>    delay(5.0);
>    Put_Line("waited for 5 secs");
>    TtyS2.Close;

> end access_dev;

> =============== package specification ==============
> package Device is
>    task type DevTask is
>       entry Open(Dev:String);
>       entry Close;
>       entry Quit;
>    end DevTask;
> end Device;
> ============== package body =======================
> with Text_Io;use Text_Io;
> with Device; use Device;
> package body Device is
>       task body DevTask is
>          Exit_Flag: Boolean := False;
>          In_Stream: File_Type;
>          Buf:       String(1..82);
>          Noc:       Integer := 0;
>       begin
>          while (Exit_Flag = False) loop
>             select
>                accept Open(Dev:String) do
>                   Put_Line("Openening Device " & Dev );
>                   Open(In_Stream,IN_FILE, "/dev/ttyS2");
>                   Put_Line("Device opened");
>                end Open;
>             or
>                accept Close do
>                   --if (Is_Open(In_Stream)) then
>                      Put_Line("Closing Device");
>                      Close(In_Stream);
>                      Put_Line("Device closed");
>             --      end if;
>                end Close;
>             or
>                accept Quit do
>                   Exit_Flag := True;
>                end Quit;
>             or
>                delay(0.0);
> --               if (Is_Open(In_Stream)) then
>                    Get_Line(In_Stream,Buf,Noc);
>                    Put_Line(Buf(1..Noc));
> --               end if;
>             end select;
>          end loop;
>        Put_line("Task terminated");
>       end DevTask;
> end Device;



Tue, 11 Nov 2003 02:16:28 GMT  
 Device file not closing on close command

Quote:
>            select
..
>            or
>               delay(0.0);
..
>            end select;

I doubt this has much to do with your problem, but you should probably be using
an "else" rather than an "or delay 0.0".

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html



Tue, 11 Nov 2003 04:42:15 GMT  
 Device file not closing on close command

Quote:


>>            select
>..
>>            or
>>               delay(0.0);
>..
>>            end select;

>I doubt this has much to do with your problem, but you should probably be using
>an "else" rather than an "or delay 0.0".

..and you probably shouldn't be using either in a tight loop, like you are
doing here. That's a busy loop. It could be that your task is hogging all the
CPU in this busy loop, and is not giving your main task a chance to call the
Quit entry. But since it isn't higher priority, and delay is supposed to act as
a scheduling point, I'd be suprised if this was the problem.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html



Tue, 11 Nov 2003 04:47:53 GMT  
 Device file not closing on close command
Using Aonix ObjectAda on Windows NT, we found that a "delay 0.0" had
no effect. I haven't tried it with the latest version of the compiler,
so I don't know if that has changed.  But, at the time we had to use
a delay of 0.02 to get it to switch.
Quote:
-----Original Message-----



>>            select
>..
>>            or
>>               delay(0.0);
>..
>>            end select;

>I doubt this has much to do with your problem, but you should probably be
using
>an "else" rather than an "or delay 0.0".
..and you probably shouldn't be using either in a tight loop, like you are
doing here. That's a busy loop. It could be that your task is hogging all
the
CPU in this busy loop, and is not giving your main task a chance to call the
Quit entry. But since it isn't higher priority, and delay is supposed to act
as
a scheduling point, I'd be suprised if this was the problem.



Tue, 11 Nov 2003 05:06:43 GMT  
 Device file not closing on close command
1) I replaced "or delay" by "else", and "else delay". No change.

2) I changed the delay to 0.02. No change.

3) Even though the task runs in a busy loop, the load remains low (How
could I implement the task without a busy loop ?).

4) Task switching seems not to be a problem, because the main procedure
always sucessfully rendezvous with the
   "close" - entry of the task ("closing device" is printed every time)

5) The serial device (gps receiver) I am using is a PCMCIA card that
behaves like a serial interface. If I run the program for the first
time, it closes the device file and terminates successfully -- any
further attempt ends in a blocking close command. This is is independent
from the delay time (I tried 0.0,0.01, and  0.2). If remove the card and
reinsert it (this reloads the serial driver), it works again for one
time. From that behaviour I would think that the blocking is either
related to the linux serial driver, or the the implementation of the
gnat library. Any comments on that ?

Quote:

> Using Aonix ObjectAda on Windows NT, we found that a "delay 0.0" had
> no effect. I haven't tried it with the latest version of the compiler,
> so I don't know if that has changed.  But, at the time we had to use
> a delay of 0.02 to get it to switch.

> -----Original Message-----



> >>            select
> >..
> >>            or
> >>               delay(0.0);
> >..
> >>            end select;

> >I doubt this has much to do with your problem, but you should probably be
> using
> >an "else" rather than an "or delay 0.0".
> ..and you probably shouldn't be using either in a tight loop, like you are
> doing here. That's a busy loop. It could be that your task is hogging all
> the
> CPU in this busy loop, and is not giving your main task a chance to call the
> Quit entry. But since it isn't higher priority, and delay is supposed to act
> as
> a scheduling point, I'd be suprised if this was the problem.



Wed, 12 Nov 2003 06:30:29 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Closed file not really closed

2. mdi app not closing down, some threads just won't close #2

3. to close or not to close?

4. close command does not clear processes (defunct jobs)

5. how to close file, how much command

6. NT Server not releasing some files on program close

7. File not being able to close

8. NI_readwriteAVI.dll does not close file reference

9. problem with expect 5.30 and log_file not closing file

10. Strange thing: file.close did not show error but work wrong

11. CW55PE release H when I close a wizard generated application the IDE closes as well

12. tcl-dp confuses expect's close call with builtin close

 

 
Powered by phpBB® Forum Software