Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > why it does not sleep?

Reply
Thread Tools

why it does not sleep?

 
 
JosephWu
Guest
Posts: n/a
 
      09-09-2004
Hi all.

I have the following code and the 1000 numbers has stored before calling
fifo(),in fifo,why it does not sleep for 1 sec ?it just stop there,but
if i delete sleep(1) ,the number will successfully printed on screen.

Thanks a lot guys!

================================================== ========

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int n[1000];//copy of 1000 numbers
//============================================

//fcfs,fifo:first in first out
void fifo(void){
int reqinter[1000];
for (int i=0;i<1000;i++){
printf("%d ",n[i]);
sleep(1);
}
}

//sst:shortest seek time
void sst(void){

}

//elev:elevator
void elev(void){

}

//cscan:circular scan
void cscan(void){

}

//============================================

//============================================
int main (int argc,char* argv[]) {
//=========get input=================
for(int i=0;i<1000;i++){
scanf("%d",&n[i]);

}

//==========begin to request==========

fifo();
sst();
elev();
cscan();

//====================================
return 0;
}

================================================== ==============
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      09-09-2004

"JosephWu" <(E-Mail Removed)> wrote in message
news:Xns955FF1E6D8C73wutongjoe@202.180.64.19...
> Hi all.
>
> I have the following code and the 1000 numbers has stored before calling
> fifo(),in fifo,why it does not sleep for 1 sec ?it just stop there,but
> if i delete sleep(1) ,the number will successfully printed on screen.
>


You probably need to flush the standard output to make sure that the output
occurs immediately. See below.

> Thanks a lot guys!
>
> ================================================== ========
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
>
> int n[1000];//copy of 1000 numbers
> //============================================
>
> //fcfs,fifo:first in first out
> void fifo(void){
> int reqinter[1000];
> for (int i=0;i<1000;i++){
> printf("%d ",n[i]);


Add this

fflush(stdout);

> sleep(1);
> }
> }
>


john


 
Reply With Quote
 
 
 
 
Moonlit
Guest
Posts: n/a
 
      09-09-2004
Hi,

"JosephWu" <(E-Mail Removed)> wrote in message
news:Xns955FF1E6D8C73wutongjoe@202.180.64.19...
> Hi all.
>
> I have the following code and the 1000 numbers has stored before calling
> fifo(),in fifo,why it does not sleep for 1 sec ?it just stop there,but
> if i delete sleep(1) ,the number will successfully printed on screen.
>
> Thanks a lot guys!
>
> ================================================== ========
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
>
> int n[1000];//copy of 1000 numbers
> //============================================
>
> //fcfs,fifo:first in first out
> void fifo(void){
> int reqinter[1000];
> for (int i=0;i<1000;i++){
> printf("%d ",n[i]);
> sleep(1);
> }
> }


Check the return value of sleep

while( sleep(1) );
Though I am not sure what happens with a one second sleep.

sleep can be interrupted on most unix systems by an interrupt and will then
return even if the time hasn't expired!
It will return the seconds that is has to go

Regards, Ron AF Greve.

>
> //sst:shortest seek time
> void sst(void){
>
> }
>
> //elev:elevator
> void elev(void){
>
> }
>
> //cscan:circular scan
> void cscan(void){
>
> }
>
> //============================================
>
> //============================================
> int main (int argc,char* argv[]) {
> //=========get input=================
> for(int i=0;i<1000;i++){
> scanf("%d",&n[i]);
>
> }
>
> //==========begin to request==========
>
> fifo();
> sst();
> elev();
> cscan();
>
> //====================================
> return 0;
> }
>
> ================================================== ==============



 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 5.38 Why does Perl let me delete read-only files? Why does "-i" clobber protected files? Isn't this a bug in Perl? PerlFAQ Server Perl Misc 0 02-11-2011 05:00 AM
Why :: ? Why not : ? Why not . ? <- less clutter ?!? Skybuck Flying C++ 16 08-25-2007 09:48 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
why why why does function not work Horace Nunley ASP .Net 1 09-27-2006 09:52 PM



Advertisments