Last active
August 29, 2015 14:20
-
-
Save aerodame/b4f2ddb5162a86a0039e to your computer and use it in GitHub Desktop.
SyncQueue for Disk I/O
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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