Skip to content

Instantly share code, notes, and snippets.

View mrnkr's full-sized avatar
🏠
Working from home

Alvaro Nicoli mrnkr

🏠
Working from home
View GitHub Profile
@mrnkr
mrnkr / read-write.swift
Created October 24, 2018 18:38
Readers and writers problem solved in swift using semaphores
import UIKit
class Semaphore {
var n: Int
init(n: Int) {
self.n = n
}
func P() {
@mrnkr
mrnkr / prod-cons.swift
Created October 24, 2018 01:54
Producer-Consumer problem implemented in Swift using Semaphores
import UIKit
class Semaphore {
var n: Int
init(n: Int) {
self.n = n
}
func P() {
@mrnkr
mrnkr / semaphore.swift
Created October 23, 2018 23:27
Semaphores for solving the mutual exclusion problem
import UIKit
class Semaphore {
var n: Int
init(n: Int) {
self.n = n
}
func P() {
@mrnkr
mrnkr / dekker.swift
Created October 23, 2018 22:41
Dekker's algorithm for mutual exclusion
import UIKit
var ran: Int = 0;
var favoredProcess: String = "first"
var processOneWantsIn: Bool = false
var processTwoWantsIn: Bool = false
func processOne(task: () -> Void) {
while ran < 50 {
processOneWantsIn = true
@mrnkr
mrnkr / peterson.swift
Created October 23, 2018 22:40
Peterson's algorithm for mutual exclusion
import UIKit
var n: Int = 0;
var favoredProcess: String = "first"
var processOneWantsIn: Bool = false
var processTwoWantsIn: Bool = false
func processOne(task: () -> Void) {
while n < 50 {
processOneWantsIn = true