Skip to content

libmid/libtandem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build & Usage

Build shared and static library using make. Build artifacts can be found in /build.

Basic Coroutine Example

#include <stdio.h>
#include "tandem/coro.h"

#define STACK_SIZE 64 * 1024

void foo(td_rt *rt) {
  for (int i = 1; i <= 10; i++) {
    printf("FOO: %d\n", i);
    td_suspend(rt);
  }
}

void bar(td_rt *rt) {
  for (int i = 2; i <= 10; i+=2) {
    printf("BAR: %d\n", i);
    td_suspend(rt);
  }
}

int main() {
  td_rt *rt = td_init();

  td_coro* coro1 = td_spawn(rt, &foo, STACK_SIZE);
  td_coro* coro2 = td_spawn(rt, &bar, STACK_SIZE);

  while (coro1->status == TD_CORO_RUNNING || coro2->status == TD_CORO_RUNNING) {
    printf("MAIN\n");
    td_resume(rt, coro1);
    td_resume(rt, coro2);
  }

  td_free(rt);
}

About

A simple asyncronous concurrency library in c

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published