Skip to content

Instantly share code, notes, and snippets.

View albertnetymk's full-sized avatar

Albert Yang albertnetymk

  • Uppsala, Sweden
View GitHub Profile

Region types in G1

Let's introduce the region types used in G1:

eden: for newly added objects from-survivor: for objects in to-survivor from previous young-GC to-survivor: live objects in eden/from-survivor are copied here if they have not lived long old: live objects in eden/from-survivor are copied here if they have lived long

#include <iostream>
#include <cassert>
using namespace std;
static int a, b, c;
int new_sum(int sum, bool& terminated)

Find the max and min of sum of all permutations of [1..9] satisfying the following condition:

    == a[1] + a[2] + a[3]
    == a[3] + a[4] + a[5]
    == a[5] + a[6] + a[7]
    == a[7] + a[8]
    where sum = a[0] + a[1]
{-# LANGUAGE NamedFieldPuns #-}
import Data.List ((\\))
type Grid = [[Char]]
third_d :: Int -> Int -> Int
third_d x y = head $ [1..3] \\ [x,y]
data Op = L | R | U | D deriving (Show)
data State = State {

Haskell lab

0. Warmup


Hoogle is the search engine for Haskell functions. It supports searching by function names and types.

For example, you plan to use parMap, but forget its type. You could just type parMap in Hoogle, and the search result would look like:

global gc_major
global gc_minor
global gc_major_count
global gc_minor_count
global stat
global count_stat
probe process("/home/albert/github/otp/bin/x86_64-unknown-linux-gnu/beam.smp").mark("gc_major__start")
gc_major[user_string($arg1)] = gettimeofday_ms() - gc_major[user_string($arg1)]

Racket lab

0 Background


DrRacket provides rudimentary features for Racket programming, you could experiment them by launch DrRacket directly. Some particularly interesting/useful ones are highlighted here:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// copied from
void insertion_sort (int *a, int n) {
int i, j, t;
for (i = 1; i < n; i++) {
t = a[i];
for (j = i; j > 0 && t < a[j - 1]; j--) {
albertnetymk /
Last active September 10, 2015 20:50

How STM interacts with locks in kappa

I would firstly assume sync block has the same semantics of pthread_mutex_lock. When the execution outside of transactions reaches sync block, it would gain exclusive access to this critical region, and all other executions, either inside or outside transactions, are blocked if they try to enter the critical region.

When the execution inside of transactions reaches sync block, it would gain non-exclusive access to this critical region, which could be obtained by any other executions inside transactions, but executions outside transactions would be blocked.

In other words, the mutex lock inside the transactions becomes a reader lock, and mutex lock outside the transactions becomes a writer lock.

class: center, middle

Synchronize with Asynchronous Computation

Albert Mingkun Yang

Block or Continuation, that's the question

  • Block: Easy to read, but waste CPU cycles