• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
File IO preventing sleep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

File IO preventing sleep


  • Subject: File IO preventing sleep
  • From: Lisa Zorn <email@hidden>
  • Date: Fri, 17 May 2002 15:18:20 -0700

Hello all,

I'm having a problem with sleep... Or my computer is. (= I have a daemon application that runs all the time in the background, and my program is preventing MacOS X's energy saver from kicking in and putting the computer to sleep.

After running some (time-consuming, alas) tests, I think I've narrowed down the problem to the fact that my daemon is polling a file for changes. To be specific, there's a thread that continually uses ifstream's getline() method to read lines; in particular, it reads to eof, then sleeps, then tries again.

So it's (roughly):
//---------------------
while (TRUE) {

while (!mystream_->eof()) {
mystream_->getline(line, SYS_BUFFER_SIZE-1);
// do stuff with the line
}
sleep(2);
}
//---------------------

(It's polling then, but it doesn't look like it affects system performance so I figured this is an acceptable way to do things.)

To try to figure out what's going on, I registered a callback with IORegisterForSystemPower. When the getline() is in the loop, I do not receive a kIOMessageCanSystemSleep. When I take getline() out (and make sure that the inner while loop exits after a number of iterations), I do receive it, and the system will sleep.

On a related note, running less on a file with the capital-F mode also seems to prevent the system from sleeping, in the same way that my program is doing.

Does anyone have any suggestions on what I should do?
Thanks for your time,
-lisa
Glucose Development Corporation -- http://www.glu.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: File IO preventing sleep
      • From: Dean Reece <email@hidden>
  • Prev by Date: Re: Cocoa Logo
  • Next by Date: Re: Cocoa Logo
  • Previous by thread: Dos anybody now how to use "setUsesThreadedAnimation" NSProgressIndicator control.
  • Next by thread: Re: File IO preventing sleep
  • Index(es):
    • Date
    • Thread