4

I've noticed this today - my entire system froze up solid, clock is frozen, nothing responds to clicks and key presses, and my time machine animation stopped going. While repartitioning my boot drive. I also had iTunes open, which happily kept on playing music. How does iTunes manage to keep playing media if the entire OS is frozen up solid? No other OS X media player I've seen can do this, and I'd love to know how this is possible.

Thanks.

2
  • I think it's always a good question to ask how one can make one's program more responsive!
    – Yuji
    Jun 11, 2011 at 4:08
  • That's true. I can not stand un-responsive programs!
    – Tristan
    Jun 11, 2011 at 4:58

2 Answers 2

4

I believe iTunes uses real-time threads, which is a certain type of threads which are given constant fraction of time whatever happens on the machine. See this apple doc for a short discussion. You can find more info in the OS X Internal book. The book is a bit dated (it mainly discusses 10.4 Tiger) but the kernel internals haven't drastically changed.

I think other media players don't operate as real-time threads; these days the computers are quite powerful and the music doesn't stop even under the standard scheduling policy, unless you do an extremely kernel-intensive task.

1
  • Thanks for the links, I've never known that OS X had more than one type of thread. I figure this must be what iTunes uses. Thanks for the response!
    – Tristan
    Jun 11, 2011 at 4:58
2

My guess is that when you select a song to play in iTunes, iTunes will push almost all of the raw data for the song into a DMA. Because of the way that I/O devices talk to the CPU, each device has it's own memory address. Once the CPU has finished pushing data to that address, the I/O device can use the data there withou the CPU having to babysit it. So iTunes moves the data for the song to the sound device's memory address and the sound device starts playing it. When the CPU locks up while you're playing a song, the sound device hasn't realized the CPU stopped, and just keeps using the data from its memory address, playing the song.

2
  • Heh, I figured that iTunes must be doing some low-level funness. But a secure OS would NOT allow (non-root) user-space applications to access memory/hardware directly now, would it?
    – Tristan
    Jun 11, 2011 at 4:57
  • 2
    Nope, that's not how iTunes works -- interesting theory, though!
    – duskwuff
    Jun 11, 2011 at 5:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .