Skip to content

Instantly share code, notes, and snippets.

View albertnetymk's full-sized avatar

Albert Yang albertnetymk

  • Uppsala, Sweden
View GitHub Profile
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <sched.h>
#define N 100
#define MSG 1000
#define THREAD 10
class Client {
server : Server
def init(s:Server) : void {
this.server = s
}
def block() : void {
get this.server.f();
}
import java.util.*;
import java.util.concurrent.*;
public class block {
static ForkJoinPool pool;
static Server s;
static Client c1, c2;
static volatile int x = 0;
static class Client extends RecursiveAction {
@Override

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
@albertnetymk
albertnetymk / STM.md
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.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// copied from http://rosettacode.org/wiki/Sorting_algorithms/Insertion_sort#C
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--) {
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)]
#define MIN(a,b) (((a)<(b))?(a):(b))
typedef unsigned int uint;
typedef struct {
uint red:5;
uint green:6;
uint blue:5;
} f_pixel;

Def of project:

specific goal specific time period specific resource unique work arrangement temporary organization

The line is optimized towards routine work. When one new problem arises, one specific request is given to a project group through a project charter trying to solve this problem. After the problem is solved, the result is implemented in the line, and initiates new work routine in the line.

diffs between project manager and line manager:

{-# 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 {