Skip to content

Instantly share code, notes, and snippets.

View ktoso's full-sized avatar
🗻
Life is Study!

Konrad `ktoso` Malawski ktoso

🗻
Life is Study!
View GitHub Profile
@DougGregor
DougGregor / preventing-data-races.md
Created December 20, 2020 06:49
Preventing Data Races in the Swift Concurrency Model

Preventing Data Races in the Swift Concurrency Model

One of the goals of the concurrency effort is to prevent data races. This document describes the approach taken to preventing data races overall, by categorizing the sources of data races and describing how they are addressed with other proposals in the Swift Concurrency effort.

Data races

A data race occurs when two threads access the same memory concurrently and at least one of the accesses can change the value. Within the safe subset of Swift (e.g., ignoring the use of UnsafeMutablePointer and related types), the memory in question is always a stored property. There are several different categories of stored properties that need to be considered for data races:

  • Global and static stored properties:

Swift compiler 4.0, language mode 4

>=4.0.0
NOT >=4.0.10
NOT >=4.0.50
NOT >=4.0.150
NOT >=4.0.200
NOT >=4.0.250
NOT >=4.1.0
import sun.misc.Unsafe;
import java.lang.reflect.Field;
import java.util.concurrent.ForkJoinPool;
/**
* @author Jakub Kubrynski
*/
public class ReplaceCommonPool {
@acolyer
acolyer / service-checklist.md
Last active June 20, 2024 08:47
Internet Scale Services Checklist

Internet Scale Services Checklist

A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."

Basic tenets

  • Does the design expect failures to happen regularly and handle them gracefully?
  • Have we kept things as simple as possible?
@johnynek
johnynek / sized_list.scala
Last active July 3, 2021 17:54
Simple example of how to write a linked-list in scala that knows its length at compile-time. This allows you to write a zip method that is always exact.
// I was reading through these examples: http://apocalisp.wordpress.com/2010/06/08/type-level-programming-in-scala/
// and I thought it would be nice to more quickly get to something useful, to show the power of the techniques.
object SizedListExample {
// Type of all Non-negative integers
sealed trait Nat
// This is zero.
sealed trait _0 extends Nat
// Successor to some non-negative number
sealed trait Succ[N <: Nat] extends Nat
@krasserm
krasserm / akka-persistence-plugins.md
Last active March 27, 2017 10:13
Akka Persistence Plugins
// or even more plain:
testCases.foreach((case) -> {
// given
Object given = case.given;
Object expected = case.expected;
it.should("return [%s] when applied to [%s]", given, expected, system -> {
// when
Object got = system.doThing(given);
@ktoso
ktoso / output.bash
Last active June 12, 2016 17:20
An proof of concept implementation to Adam's "what if we just used the types" blog post http://www.warski.org/blog/2013/01/dry-parameter-names/
ktoso@moon /Users/ktoso
$ scalac vals_by_types.scala
warning: there were 2 deprecation warnings; re-run with -deprecation for details
one warning found
ktoso@moon /Users/ktoso
$ scala Main
The combined names are: UserFinder and UserStatusReader
/**
* "Select" off the first future to be satisfied. Return this as a
* result, with the remainder of the Futures as a sequence.
*
* @param fs a scala.collection.Seq
*/
def select[A](fs: Seq[Future[A]])(implicit ec: ExecutionContext): Future[(Try[A], Seq[Future[A]])] = {
@tailrec
def stripe(p: Promise[(Try[A], Seq[Future[A]])],
heads: Seq[Future[A]],