Skip to content

Instantly share code, notes, and snippets.

View banderson623's full-sized avatar

Brian Anderson banderson623

  • Gain Compliance
  • Rocklin, CA
View GitHub Profile
@banderson623
banderson623 / Problem2.rb
Last active December 14, 2015 01:59
My dirty cpu simulator. Comment out debug lines at the bottom for displaying cool things
# Consider a system running ten I/O-bound tasks and one CPU-bound task.
# Assume that the I/O-bound tasks issue an I/O operation once for every millisecond of CPU computing and that each I/O operation takes 10 milliseconds to complete; the CPU-bound task performs only computations.
# Also assume that the context-switching overhead is 0.1 milli-second and that all processes are long-running tasks.
#
# Find out the CPU utilization for a round-robin scheduler when:
#
# a. The time quantum is 1 millisecond
#
# b. The time quantum is 10 milliseconds
@banderson623
banderson623 / Histogram.java
Created March 13, 2013 02:40
My threaded histogram
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.*;
/**
* Creates a histogram of ASCII character counts for text files.
*/
public class Histogram
{
/**
@banderson623
banderson623 / Histogram.java
Created March 13, 2013 03:26
Revised, with less array copies. I didn't know I could use a primiteve array (int[]) as a generic/template type. Awesome.
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.*;
/**
* Creates a histogram of ASCII character counts for text files.
*/
public class Histogram
{
/**
@banderson623
banderson623 / Histogram.java
Created March 13, 2013 04:08
I added a cheat :) so that pools are only used after a certain size
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.*;
/**
* Creates a histogram of ASCII character counts for text files.
*/
public class Histogram
{
@banderson623
banderson623 / part1.c
Created March 13, 2013 07:38
This is part 1 with some extra consumers. Runs on OS X too.
// 1. (70pts) Develop a monitor in C (using pthread library functions) or Java to solve the producer-consumer problem. [Hint: your program can be cased on the pseudo-code on Page 7 of 2013-3-4's lecture]
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <semaphore.h>
#define CAN_CONSUME_PATH "/tmp/canConsume"
#define CAN_PRODUCE_PATH "/tmp/canProduce"
@banderson623
banderson623 / monitor.c
Last active December 5, 2020 16:29
Here is my final (?) monitor implementation in C.
/**
* Brian Anderson, Spring 2013
* Com S 352, Assignment 7
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* INTRODUCTION & PURPOSE
* -------------------------------------------------------------------
* Create a monitor library fashioned after the slides shown in class.
* It solves the producer/consumer problem by making sure their
* execution happens in a safe manner, even across multiple threads
@banderson623
banderson623 / WritersPriority.png
Last active December 14, 2015 23:08
Solving Homework 7, part 2 See Diagram of interactions: https://www.dropbox.com/s/8bk1kiidhkxxhph/WritersPriority.png
WritersPriority.png
@banderson623
banderson623 / CalculatorProxy.java
Created March 15, 2013 18:26
Java is the Future<Language>()
import async.IAsyncCalculator;
import async.ICallback;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
/*
* Brian Anderson, Com S 352 Project 1
* UThread a User Thread Library, it uses only 1 "kernel thread"
*/
#ifdef __APPLE__
#define _XOPEN_SOURCE /* See note at the bottom about this */
#endifult_activeContext
Brian Anderson
ComS 352, Assignment 8
March, 28th, 2013
-------------------------------------------------------------------------------
1.A. Deadlock happens between the P1 and P2 during the following sequence.
P1 locks s1, 1.1
(p1 access x) 1.2
p2 locks s2 2.1
(p2 access y) 2.2