public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* program 'hangs' when running several instances of program for writing to a file...
@ 2003-06-16 18:53 Hilda Klasky
  2003-06-18 17:17 ` Claudio Bley
  0 siblings, 1 reply; 2+ messages in thread
From: Hilda Klasky @ 2003-06-16 18:53 UTC (permalink / raw)
  To: gcc-help

Hi Everyone, I hope some one could help me please.

I am using:

Red Hat 9.0
Kernel 2.4.20-8
gcc 3.2.2

My program writes to a file 25K of data every 25 milliseconds. It optionally
flushes the buffer as specified by the user on the entry parameters.

The problem I have is that, when I attempt to run two instances of the
program, (each one writes to a different file); one of the process 'hangs'
(stops writing to the file), when I select the flush option to be on.

When I select the flush option to be off, and I run more than 2 instances of
the program, one of the process 'hangs' also.

I wonder if some how I am over loading some buffer.
I will appreciate your help. Thank you very much in advance.

The core of my code follows:

for (i=0;i<4000;i++){
         //get the time
         t1=microseconds();
         //write the block of data
         of.write(buffer, (unsigned int) read_size);

         if (flush){
             of.flush();
         }//flush

         //get the time again
         t2=microseconds();

         //sleep time:
         long int sleept = floor( ((t1+d)-t2)*1000);
         usleep( sleept );
         //end of sleep time

      }//for i=1 to ..


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: program 'hangs' when running several instances of program for writing to a file...
  2003-06-16 18:53 program 'hangs' when running several instances of program for writing to a file Hilda Klasky
@ 2003-06-18 17:17 ` Claudio Bley
  0 siblings, 0 replies; 2+ messages in thread
From: Claudio Bley @ 2003-06-18 17:17 UTC (permalink / raw)
  To: gcc-help

On Mon, Jun 16, 2003 at 02:54:19PM -0400, Hilda Klasky wrote:
> Hi Everyone, I hope some one could help me please.
> 

Hi.

> My program writes to a file 25K of data every 25 milliseconds. It optionally
> flushes the buffer as specified by the user on the entry parameters.
> 
> The problem I have is that, when I attempt to run two instances of the
> program, (each one writes to a different file); one of the process 'hangs'
> (stops writing to the file), when I select the flush option to be on.
> 
> When I select the flush option to be off, and I run more than 2 instances of
> the program, one of the process 'hangs' also.
> 
> I wonder if some how I am over loading some buffer.
> I will appreciate your help. Thank you very much in advance.
> 
> The core of my code follows:
> 
> for (i=0;i<4000;i++){
>          //get the time
>          t1=microseconds();
>          //write the block of data
>          of.write(buffer, (unsigned int) read_size);
> 
>          if (flush){
>              of.flush();
>          }//flush
> 
>          //get the time again
>          t2=microseconds();
> 
>          //sleep time:
>          long int sleept = floor( ((t1+d)-t2)*1000);
>          usleep( sleept );
>          //end of sleep time
> 
>       }//for i=1 to ..

The usleep function expects an `unsigned long' as parameter. You are
passing a `long int' to it which can be negative and gets implicitly
converted to `unsigned long' when passed to the function. 

Remember that disk I/O takes a long time (especially when you force to
flush the buffers) and 25 milliseconds might not be enough.

If t2 is greater than (t1+d) then `sleept' will be negative. Converted
to an `unsigned long' this is usually a very large number hence your
program will just sleep for quite a long time...

HTH
-- 
Claudio Bley                                 ASCII ribbon campaign (")
Debian GNU/Linux user                         - against HTML email  X 
http://www.cs.uni-magdeburg.de/~bley/                     & vCards / \

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-06-18 17:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-16 18:53 program 'hangs' when running several instances of program for writing to a file Hilda Klasky
2003-06-18 17:17 ` Claudio Bley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).