Skip to content

Instantly share code, notes, and snippets.

public class Deadlock {
public Deadlock( ) {
Mutex mutex[] = new Mutex[4];
for ( int i = 0; i < 4; i++ )
mutex[i] = new Mutex( );
A threadA = new A( mutex );
B threadB = new B( mutex );
public class Deadlock {
public Deadlock( ) {
Mutex mutex[] = new Mutex[4];
for ( int i = 0; i < 4; i++ )
mutex[i] = new Mutex( );
A threadA = new A( mutex );
B threadB = new B( mutex );
C threadC = new C( mutex );
// Provide a quick debugger of the TCBs in queue
// Format of output is = Q[i]-> { [p,t] [p,t] [p,t] ... }
private void dumpQueue(int time) {
int N;
if (DEBUG) {
System.out.print("T("+time+"): ");
// scan through each multilevel queue
for (int i=0; i < 3; i++) {
// how many TCBs are in queue
N = queue[i].size();
@aerodame
aerodame / ThreadDriver.java
Last active August 29, 2015 14:18
CSS430 - Program1 Thread Main
public class ThreadDriver {
public static void main( String[] args ) {
String args[2];
args[0] = "ping"; args[1] = "10000";
new PingPong( args ).start( );
args[0] = "PING"; args[1] = "90000";
new PingPong( args ).start( );
}
@aerodame
aerodame / PingPong.java
Last active August 29, 2015 14:18
CSS430 - Program 1 - PingPong
public class PingPong extends Thread {
private String word;
private int loop;
public PingPong( String[] args ) {
word = args[0];
loop = Integer.parseInt( args[1] );
}
public void run( ) {
for ( int j = 0; j < 100; j++ ) {
SysLib.cout( word + " " );
@aerodame
aerodame / PingPong.java
Created April 1, 2015 07:13
CSS430 : Program 1 - PingPong Infinite
public class PingPong extends Thread {
private String word;
private int loop;
public PingPong( String[] args ) {
word = args[0];
loop = Integer.parseInt( args[1] );
}
public void run( ) {
for ( int j = 0; j < 100; j++ ) {
SysLib.cout( word + " " );
@aerodame
aerodame / gist:c1dc6c7a1b6b28815361
Last active August 29, 2015 14:19
ThreadOS Single Queue debugger
// ----------------------- Start Debugger Method ---------------------------
// Provide a simple debugger of the TCBs in queue
// Format of output is = Q[]-> { [p,t] [p,t] [p,t] ... }
// Where p = Process ID
// t = Thread ID
// -------------------------------------------------------------------------
private void dumpQueue(int time) {
if (DEBUG) {
System.out.print("\nT("+time+"): ");
// how many TCBs are in queue
@aerodame
aerodame / DiskIO_Snippet.java
Last active August 29, 2015 14:20
Disk IO Sync Snippet
Disk disk = new Disk( 1000 );
// a disk read operation:
while ( disk.read( blockId, buffer ) == false )
; // busy wait
while ( disk.testAndResetReady( ) == false )
; // another busy wait
// now you can access data in buffer
@aerodame
aerodame / KernelSnippet.java
Last active August 29, 2015 14:20
ThreadOS Kernel Snippet
import java.util.*;
import java.lang.reflect.*;
import java.io.*;
public class Kernel {
// Interrupt requests
public final static int INTERRUPT_SOFTWARE = 1; // System calls
public final static int INTERRUPT_DISK = 2; // Disk interrupts
public final static int INTERRUPT_IO = 3; // Other I/O interrupts
@aerodame
aerodame / Kernel_Disk.java
Last active August 29, 2015 14:20
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