Giter VIP home page Giter VIP logo

ats-task's Introduction

Lightweight tasks module for ATS

This is a cooperative tasks module for ATS where the tasks are implemented using ucontext switches.

Install

The library is best used by cloning from under a parent directory that is used to store ATS libraries. This directory can then be passed to the 'atscc' command line using the '-I' and '-IATS' options to be added to the include path. In the examples below this directory is $ATSCCLIB.

cd $ATSCCLIB
git clone git://github.com/doublec/ats-task task
cd task
make

Usage

The first step is to create a task scheduler and install this as the global scheduler:

var sch = scheduler_new ()
val () = set_global_scheduler (sch)

Once this is done tasks can be spawned. 'task_spawn' takes a stack size and a linear closure (cloptr1) that is run when the task is scheduled:

val () = task_spawn (16384, lam () => {
                        val () = print ("hello\n")
                        val () = task_yield ()
                        val () = print ("world\n")
                     })

Tasks can yield using 'task_yield' which results in switching to the next task waiting to run, and scheduling itself to run again later.

The task scheduler needs to be activated with:

val () = run_global_scheduler ()

The scheduler exits when no more tasks are queued. The global scheduler must be unset and free'd:

val () = unset_global_scheduler (sch)
val () = scheduler_free (sch)

A compile error reults if the scheduler is not unset or free'd.

TODO

  • Make set_global_scheduler set it for the current CPU thread, allowing a scheduler to run per CPU.
  • Add intertask communication via channels.
  • Integrate with my ATS libevent wrapper to allow writing libevent based applications in a non-callback style. This was my original motivation for writing this library. This is now partially supported. See the 'test2' example in the TEST directory which demonstrates downloading URL's using libevent without using callbacks in the main code (See the 'do_main' function).

Contact

ats-task's People

Contributors

doublec avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.