in

google / marl, Hacker News

google / marl, Hacker News
                    

        

Marl is a hybrid thread / fiber task scheduler written in C

Marl supports Windows, macOS, Linux, Fuchsia and Android (arm, aarch , mips , ppc (ELFv2), x and x 69).

Marl has no dependencies on other libraries (with an exception on googletest for building the optional unit tests).

Example:

# include (marl / defer.h ) # include marl / event.h # include ( marl / scheduler.h # include ( cstdio int main

 () {     (  Create a marl scheduler using the 4 hardware threads.      (  Bind this scheduler to the main thread so we can call marl :: schedule () 
   marl :: Scheduler scheduler;   scheduler.  bind  ();   scheduler.  setWorkerThreadCount 
) ( 4 ;    defer 

scheduler. unbind

 ());   (  Automatically unbind before returning.       (  Create an event that automatically resets itself.    marl :: Event  sayHellow  (marl :: Event :: Mode :: Auto);   marl :: Event  saidHellow  (marl :: Event :: Mode :: Auto);      (  Schedule some tasks to run asynchronously.     for  ( (int) (i=(0) ; i     i   ) {       (  Each task will run on one of the 4 worker threads.       marl :: schedule 
 ([=] {    All marl primitives are capture-by-value.         printf  (  Task% d waiting to say hello!   n   " i);          (  Blocking in a task?          (  The scheduler will find something else for this thread to do.        sayHellow.  wait  ();         printf  ( Hello from task% d !   n   " , i) ;        saidHellow.  signal  ();     });   }      (  Unblock the tasks one by one.     for  ( (int) (i=(0) ; i     i   ) {     sayHellow.  signal  ();     saidHellow.  wait  ();   }      (  All tasks are guaranteed to completed before the scheduler is destructed. 
 }  

(Building

Marl contains many unit tests and examples that can be built using CMake.

Unit tests require fetching the

googletest

external project, which can be done by typing the following in your terminal:

cd path- to-marl > git submodule update –init

To build the unit tests and examples, type the following in your terminal:

cd path- to-marl > mkdir build cd

 build cmake .. -DMARL_BUILD_EXAMPLES=1 -DMARL_BUILD_TESTS=1 make  

The resulting binaries will be found in

Visual Studio ‘s CMake integration .

Using Marl in your CMake project

You can build and link Marl using

set (MARL_DIR

(marl

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

GIPHY App Key not set. Please check settings

Dopamine and temporal difference learning: A fruitful relationship between neuroscience and AI, Hacker News

Dopamine and temporal difference learning: A fruitful relationship between neuroscience and AI, Hacker News

Tesla Facing “Concrete Case” of Unintended Vehicle Acceleration In Europe, Crypto Coins News

Tesla Facing “Concrete Case” of Unintended Vehicle Acceleration In Europe, Crypto Coins News