Skip to content

Instantly share code, notes, and snippets.

View albertnetymk's full-sized avatar

Albert Yang albertnetymk

  • Uppsala, Sweden
View GitHub Profile
@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.

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
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 Client {
server : Server
def init(s:Server) : void {
this.server = s
}
def block() : void {
get this.server.f();
}
#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