• Stars
    star
    131
  • Rank 275,867 (Top 6 %)
  • Language
    C
  • License
    Apache License 2.0
  • Created over 11 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Implementing coroutines, channels, message passing, etc.

This was originally a one-day project to explore implementing concurrency in C. This is all exploratory code which isn't even close to production ready. On the first day, we tried implementing the most naive possible implemenation of coroutines, allocating a fixed amount of extra stack space, fixing a particular amount of stack space for each coroutine, giving each coroutine EXTRA_SPACE / N stack space, for some fixed N.

On top of that, we implemented channels (for something resembling Go style concurrency), again using the dumbest possible implementation. A send or receive on a channel simply marks a coroutine unrunnable in the channel scheduler until the channel sees the inverse operation.

A few days later, we spent half a day creating the second simplest coroutine implementation we could think of: allocate space on the heap for each coroutine, and swap stacks when switching between coroutines. Turns out, this is what the Julia language does, so this idea turned out to be more practical than we realized.

A possible improvement would be to allocate a seperate stack space for each coroutine. The most obvious way to do that would be to use ucontext, but that doesn't appear to have good cross-platform support. In particular, the Mac OS X implementation seems to be fundamentally broken. I played around with sigaltstack as an alternative. That ought to work, and I may try implementing coroutines on top of sigaltstack at some point.

  • coroutines.*: Implementation of coroutines using setjmp and longjmp
  • coroutine_test.c: Simple usage of above
  • heapros.c: Implementaion of coroutines using setjmp and longjmp, with stack copying to heap
  • channels.: Implementation of channels, on top of coroutines.
  • channel_test.c: Sieve of Eratosthenes using channels
  • stack_engine_ubenchmark.c: Silly benchmark to figure out if manually messing with stack will cause performance degradation, by causing sync uops to be inserted to keep Intel's "stack engine" in sync with back-end stack registers
  • sigaltstack.c: Use sigaltstack to change stack
  • setjmp.c, exception.c, coop.c: Setjmp/longjmp examples from wikipedia

Run:

git submodule update --init

More Repositories

1

post-mortems

A collection of postmortems. Sorry for the delay in merging PRs!
10,556
star
2

debugging-stories

A collection of debugging stories. PRs welcome (sorry for the backlog) :-)
3,589
star
3

UFLDL-tutorial

Deep Learning and Unsupervised Feature Learning Tutorial Solutions
Jupyter Notebook
389
star
4

malloc-tutorial

A quick tutorial on how to implement malloc/free/calloc/realloc
C
150
star
5

storrent

Toy scala/akka Bittorrent client. Written while learning scala and now unmaintained
Scala
76
star
6

sega-system-for-fpga

FPGA Sega in Verilog, for Xilinx Virtex, circa 2002. Has an emulator thrown in, to simplify FPGA debugging.
Assembly
68
star
7

Fuzz.jl

World's dumbest fuzzer
Julia
50
star
8

akka-concurrency-wyatt

Worked through Derek Wyatt's Akka Concurrency book
Scala
47
star
9

dump

Experiments and preliminary implementations of things
PostScript
23
star
10

fs-errors

Reproducing resuts from old papers on modern filesystems
Python
22
star
11

julia-cookbook

julialang cookbook
CSS
16
star
12

ninety-nine-scala-problems

Solutions and tests for Phil Gold's S-99: Ninety-Nine Scala Problems
Scala
14
star
13

secvisor-formal-verification

Formal verification of SecVisor, a secure hypervisor
Common Lisp
12
star
14

gnu-pth

Copy of latest source from http://ftp.gnu.org/gnu/pth/
C
10
star
15

ncverilog-error-messages

Explanation of ncverilog error messages. Nothing fancy; just a text file.
9
star
16

danluu-hugo-theme

Basic blog theme, "works for me"-quality. This is only here because someone wanted a copy; I don't suggest that you use it :-)
HTML
8
star
17

neural-nets-101

Just playing around with basic neural net stuff, with a brief sojourn into deep learning via RBMs
MATLAB
6
star
18

madison-hack-and-tell

Madison Hack and Tell presentations
5
star
19

hydra

Fork of Hydra source
Haskell
4
star
20

verilog-dump

Verilog
4
star
21

ocaml-llvm-tutorial

Working through Erick Tryzelaar's LLVM tutorial
OCaml
3
star
22

buzzword-bingo

Buzzword bingo game from 1993
C
2
star
23

bluespec-tutorials

Playing around with some bluespec tutorials
2
star
24

mta-analysis

Protocol Buffer
2
star
25

hello-world

Just working through the tutorial at http://blog.ksplice.com/2010/03/libc-free-world/
C
2
star
26

Xv6

Copy of http://pdos.csail.mit.edu/6.828/2012/xv6.html
C
2
star
27

thompson-haskell

Exercises from Thompson's "Haskell: The Craft of Functional Programming"
Haskell
2
star
28

dineroIV

Repo for some experiments using dineroIV
C
2
star
29

csv

Testing CSV implementations
Python
1
star
30

Project-Euler

Learning F# and bluespec via Project Euler
F#
1
star
31

julia-metaprogramming

1
star
32

config

.emacs, and perhaps some other things
Emacs Lisp
1
star
33

isotropic

Client/server code from an early version of isotropic
Python
1
star
34

notes

1
star
35

n2t

nand2tetris, verilog
Verilog
1
star
36

rust-experiments

Learning rust
Rust
1
star
37

latency

An abandoned experiment
Python
1
star
38

kodkod-clj

Messing around with a SAT solver in clojure
Clojure
1
star