Skip to content

Instantly share code, notes, and snippets.

@aerodame
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save aerodame/b4f2ddb5162a86a0039e to your computer and use it in GitHub Desktop.

Select an option

Save aerodame/b4f2ddb5162a86a0039e to your computer and use it in GitHub Desktop.
SyncQueue for Disk I/O
Disk disk = new Disk( 1000 );
SyncQueue ioQueue = new SyncQueue( );
...
...
// a disk read operation:
while ( disk.read( blockId, buffer ) == false ) {
ioQueue.enqueueAndSleep( 1 ); // relinquish CPU to another ready thread
// now check to ensure disk is not busy
while ( disk.testAndResetReady( ) == false )
ioQueue.enqueueAndSleep( 2 ); // relinquish CPU to another ready thread
}
// now you can access data in buffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment