This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: program 'hangs' when running several instances of program for writing to a file...


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 / \


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]