Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

©️ Concurrent Programming Library (Coroutine) for C11

License

NotificationsYou must be signed in to change notification settings

sharow/libconcurrent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zlib License

tiny asymmetric-coroutine library.

Description

  • asymmetric-coroutine
  • bidirectional communication byyield_value/resume_value
  • native context switch
  • C11

Supported Platforms

x86_64i686ARM(v6/v7)AArch64(contributor)
Linux✔️✔️✔️✔️
FreeBSD✔️✔️@t6
OSX✔️✖️✖️✔️@kpamnany
(contributor)@mitghi

Code Example

#include<stdio.h>#include<stdlib.h>#include<stdint.h>#include<stdnoreturn.h>#include<concurrent/concurrent.h>#include<concurrent/shortname.h>#defineSTACK_SIZE (1024 * 2)noreturnvoidaccumulator(structconcurrent_ctx*ctx){int*v=ctx_get_resume_value(ctx);inttotal=*v;for (;;) {v=yield_value(ctx,&total);// send total / receive next valuetotal+=*v;    }}intmain(void){structconcurrent_ctx*ctx;uint8_tstack[STACK_SIZE];uint8_tctx_alloc[ctx_sizeof()];concurrent_init();ctx= (structconcurrent_ctx*)ctx_alloc;ctx_construct(ctx,stack,STACK_SIZE,accumulator,NULL);for (inti=1;i <=10;i++) {int*total=resume_value(ctx,&i);// send value / receive totalprintf("total = %d\n",*total);            }ctx_destruct(ctx);concurrent_fin();returnEXIT_SUCCESS;}/*$ gcc -o sample sample.c -lconcurrent.a$ ./sampletotal = 1total = 3total = 6total = 10total = 15total = 21total = 28total = 36total = 45total = 55*/

Requirements for build

  • for x86_64/i686:nasm

Installation

$ git clone https://github.com/sharow/libconcurrent.git libconcurrent$ cd libconcurrent$ make$ sudo make install

for FreeBSD

Available in ports collection asdevel/libconcurrent

for OSX

$ brew install nasm

Tests

$ make test

Benchmark

examples/many_context1.c:

-- output: (Xeon E3 2.5Ghz)3000000 context switch in 373.5 msone context switch in 125 ns8031333 resume/yield pair per second-- output: (RaspberryPi2 ARMv7 900MHz)3000000 context switch in 2861.8 msone context switch in 954 ns1048287 resume/yield pair per second

VS.

About

©️ Concurrent Programming Library (Coroutine) for C11

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp