All Projects → vegardit → haxe-concurrent

vegardit / haxe-concurrent

Licence: Apache-2.0 license
A haxelib for basic platform-agnostic concurrency support

Programming Languages

haxe
709 projects
Batchfile
5799 projects

Projects that are alternatives of or similar to haxe-concurrent

YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (+179.71%)
Mutual labels:  executor, scheduler, thread, concurrency, thread-pool
Java Concurrency Examples
Java Concurrency/Multithreading Tutorial with Examples for Dummies
Stars: ✭ 173 (+150.72%)
Mutual labels:  thread, concurrency, lock, thread-pool
Transmittable Thread Local
📌 TransmittableThreadLocal (TTL), the missing Java™ std lib(simple & 0-dependency) for framework/middleware, provide an enhanced InheritableThreadLocal that transmits values between threads even using thread pooling components.
Stars: ✭ 4,678 (+6679.71%)
Mutual labels:  executor, thread, thread-pool
Concurrency
Java 并发编程知识梳理以及常见处理模式 features and patterns
Stars: ✭ 495 (+617.39%)
Mutual labels:  thread, concurrency, thread-pool
Redisson
Redisson - Redis Java client with features of In-Memory Data Grid. Over 50 Redis based Java objects and services: Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Publish / Subscribe, Bloom filter, Spring Cache, Tomcat, Scheduler, JCache API, Hibernate, MyBatis, RPC, local cache ...
Stars: ✭ 17,972 (+25946.38%)
Mutual labels:  executor, scheduler, lock
Threadly
A library of tools to assist with safe concurrent java development. Providing unique priority based thread pools, and ways to distrbute threaded work safely.
Stars: ✭ 196 (+184.06%)
Mutual labels:  scheduler, concurrency, thread-pool
AtomicKit
Concurrency made simple in Swift.
Stars: ✭ 88 (+27.54%)
Mutual labels:  thread, concurrency, lock
Hamsters.js
100% Vanilla Javascript Multithreading & Parallel Execution Library
Stars: ✭ 517 (+649.28%)
Mutual labels:  thread, concurrency, thread-pool
Concurrent Programming
🌵《实战java高并发程序设计》源码整理
Stars: ✭ 562 (+714.49%)
Mutual labels:  thread, concurrency, thread-pool
Mt
tlock, RWMUTEX, Collab, USM, RSem and other C++ templates for Windows to provide read/write mutex locks, various multithreading tools, collaboration, differential updates and more
Stars: ✭ 18 (-73.91%)
Mutual labels:  thread, concurrency, lock
Swiftcoroutine
Swift coroutines for iOS, macOS and Linux.
Stars: ✭ 690 (+900%)
Mutual labels:  scheduler, thread
Marl
A hybrid thread / fiber task scheduler written in C++ 11
Stars: ✭ 1,078 (+1462.32%)
Mutual labels:  scheduler, thread-pool
Bree
🚥 The best job scheduler for Node.js and JavaScript with cron, dates, ms, later, and human-friendly support. Works in Node v10+ and browsers, uses workers to spawn sandboxed processes, and supports async/await, retries, throttling, concurrency, and graceful shutdown. Simple, fast, and lightweight. Made for @ForwardEmail and @ladjs.
Stars: ✭ 933 (+1252.17%)
Mutual labels:  scheduler, concurrency
Cortex M Rtic
Real-Time Interrupt-driven Concurrency (RTIC) framework for ARM Cortex-M microcontrollers
Stars: ✭ 623 (+802.9%)
Mutual labels:  scheduler, concurrency
django-concurrency-talk
🎭 Database Integrity in Django: Safely Handling Critical Data in Distributed Systems
Stars: ✭ 49 (-28.99%)
Mutual labels:  concurrency, lock
bascomtask
Lightweight parallel Java tasks
Stars: ✭ 49 (-28.99%)
Mutual labels:  thread, concurrency
async
Synchronization and asynchronous computation package for Go
Stars: ✭ 104 (+50.72%)
Mutual labels:  concurrency, lock
Concurrencpp
Modern concurrency for C++. Tasks, executors, timers and C++20 coroutines to rule them all
Stars: ✭ 340 (+392.75%)
Mutual labels:  scheduler, concurrency
practice
Java并发编程与高并发解决方案:http://coding.imooc.com/class/195.html Java开发企业级权限管理系统:http://coding.imooc.com/class/149.html
Stars: ✭ 39 (-43.48%)
Mutual labels:  executor, concurrency
akali
C++ Common Library for Windows, Linux.
Stars: ✭ 34 (-50.72%)
Mutual labels:  thread, thread-pool

haxe-concurrent - cross-platform concurrency support

Build Status Release License Contributor Covenant

  1. What is it?
  2. hx.concurrent.atomic package
  3. hx.concurrent.collection package
  4. hx.concurrent.executor package
  5. hx.concurrent.event package
  6. hx.concurrent.lock package
  7. hx.concurrent.thread package
  8. Installation
  9. Using the latest code
  10. License
  11. Alternatives

What is it?

A haxelib that provides some basic platform agnostic concurrency support.

All classes are located in the package hx.concurrent or below.

The library has been extensively unit tested (over 400 individual test cases) on the targets C++, C#, Eval, Flash, HashLink, Java, JavaScript (Node.js and PhantomJS), Lua, Neko, PHP 7 and Python 3.

Note:

  • When targeting Flash the option -swf-version 11.5 (or higher) must be specified, otherwise you will get Class flash.concurrent::Condition could not be found.
  • When targeting C# the option -D net-ver=45 must be specified, otherwise you may get error CS0234: The type or namespace name 'Volatile' does not exist in the namespace 'System.Threading'. Are you missing an assembly reference?

Haxe compatibility

haxe-concurrent Haxe
1.0.0 to 1.2.0 3.2.1 or higher
2.0.0 to 2.1.3 3.4.2 or higher
3.0.0 or higher 4.0.5 or higher
4.0.0 or higher 4.2.0 or higher

The hx.concurrent.atomic package

The hx.concurrent.atomic package contains mutable value holder classes that allow for thread.safe manipulation:

The hx.concurrent.collection package

The hx.concurrent.collection package contains thread-safe implementations of different types of collections:

The hx.concurrent.executor package

The hx.concurrent.executor package contains Executor implementations that allow to execute functions concurrently and to schedule tasks for later/repeated execution.

On platform with the thread support (C++, C#, Eval, HashLink, Neko, Python, Java) threads are used to realize true concurrent execution, on other platforms haxe.Timer is used to at least realize async execution.

import hx.concurrent.executor.Schedule;
import hx.concurrent.executor.Executor;

class Test {

   static function main() {
      var executor = Executor.create(3);  // <- 3 means to use a thread pool of 3 threads on platforms that support threads
      // depending on the platform either a thread-based or timer-based implementation is returned

      // define a function to be executed concurrently/async/scheduled (return type can also be Void)
      var myTask=function():Date {
         trace("Executing...");
         return Date.now();
      }

      // submit 10 tasks each to be executed once asynchronously/concurrently as soon as possible
      for(i in 0...10) {
         executor.submit(myTask);
      }

      executor.submit(myTask, ONCE(2000));            // async one-time execution with a delay of 2 seconds
      executor.submit(myTask, FIXED_RATE(200));       // repeated async execution every 200ms
      executor.submit(myTask, FIXED_DELAY(200));      // repeated async execution 200ms after the last execution
      executor.submit(myTask, HOURLY(30));            // async execution 30min after each full hour
      executor.submit(myTask, DAILY(3, 30));          // async execution daily at 3:30
      executor.submit(myTask, WEEKLY(SUNDAY, 3, 30)); // async execution Sundays at 3:30

      // submit a task and keep a reference to it
      var future = executor.submit(myTask, FIXED_RATE(200));

      // check if a result is already available
      switch(future.result) {
         case SUCCESS(value, time, _): trace('Successfully execution at ${Date.fromTime(time)} with result: $value');
         case FAILURE(ex, time, _):    trace('Execution failed at ${Date.fromTime(time)} with exception: $ex');
         case NONE(_):                 trace("No result yet...");
      }

      // check if the task is scheduled to be executed (again) in the future
      if(!future.isStopped) {
         trace('The task is scheduled for further executions with schedule: ${future.schedule}');
      }

      // cancel any future execution of the task
      future.cancel();
   }
}

The hx.concurrent.event package

The hx.current.event package contains classes for type-safe event dispatching.

import hx.concurrent.event.AsyncEventDispatcher;
import hx.concurrent.event.SyncEventDispatcher;
import hx.concurrent.Future;
import hx.concurrent.executor.Executor;

class Test {

   static function main() {
      /**
       * create a dispatcher that notifies listeners/callbacks synchronously in the current thread
       */
      var syncDispatcher = new SyncEventDispatcher<String>(); // events are of type string

      // create event listener
      var onEvent = function(event:String):Void {
         trace('Received event: $event');
      }

      syncDispatcher.subscribe(onEvent);

      // notify all registered listeners synchronously,
      // meaning this method call blocks until all listeners are finished executing
      syncDispatcher.fire("Hey there");

      /**
       * create a dispatcher that notifies listeners asynchronously using an executor
       */
      var executor = Executor.create(5); // thread-pool with 5 threads
      var asyncDispatcher = new AsyncEventDispatcher<String>(executor);

      // create event listener
      var onAsyncEvent = function(event:String):Void {
         trace('Received event: $event');
      }

      // notify all registered listeners asynchronously,
      // meaning this method call returns immediately
      asyncDispatcher.fire("Hey there");

      // fire another event and get notified when all listeners where notified
      var future = asyncDispatcher.fire("Boom");

      asyncDispatcher.subscribe(onAsyncEvent);

      future.onResult = function(result:FutureResult<Dynamic>) {
         switch(result) {
            case SUCCESS(count, _): trace('$count listeners were successfully notified');
            case FAILURE(ex, _): trace('Event could not be delivered because of: $ex');
            case NONE(_): trace("Nothing is happening");
          }
      };

   }
}

The hx.concurrent.lock package

The hx.concurrent.lock package contains lock implementations for different purposes:

The hx.concurrent.thread package

The hx.concurrent.thread package contains classes for platforms supporting threads:

  • ThreadPool - basic thread-pool implementation supporting C++, C#, HashLink, Neko, Java and Python. For advanced concurrency or cross-platform requirements use Executor instead.

    import hx.concurrent.thread.*;
    
    class Test {
    
       static function main() {
          var pool = new ThreadPool(4); // 4 concurrent threads
    
          pool.submit(function(ctx:ThreadContext) {
             // do some work here
          });
    
          pool.awaitCompletion(30 * 1000); // wait 30 seconds for all submitted tasks to be processed
    
          pool.cancelPendingTasks(); // cancels execution of all currently queued tasks
    
          // initiate graceful stop of all running threads, i.e. they finish the current tasks they process
          // execution of all other queued tasks is cancelled
          pool.stop();
       }
    }
  • Threads

Installation

  1. install the library via haxelib using the command:

    haxelib install haxe-concurrent
    
  2. use in your Haxe project

    • for OpenFL/Lime projects add <haxelib name="haxe-concurrent" /> to your project.xml
    • for free-style projects add -lib haxe-concurrent to your *.hxml file or as command line option when running the Haxe compiler

Using the latest code

Using haxelib git

haxelib git haxe-concurrent https://github.com/vegardit/haxe-concurrent main D:\haxe-projects\haxe-concurrent

Using Git

  1. check-out the main branch

    git clone https://github.com/vegardit/haxe-concurrent --branch main --single-branch D:\haxe-projects\haxe-concurrent
    
  2. register the development release with Haxe

    haxelib dev haxe-concurrent D:\haxe-projects\haxe-concurrent
    

Using Subversion

  1. check-out the trunk

    svn checkout https://github.com/vegardit/haxe-concurrent/trunk D:\haxe-projects\haxe-concurrent
    
  2. register the development release with haxe

    haxelib dev haxe-concurrent D:\haxe-projects\haxe-concurrent
    

License

All files are released under the Apache License 2.0.

Individual files contain the following tag instead of the full license text:

SPDX-License-Identifier: Apache-2.0

This enables machine processing of license information based on the SPDX License Identifiers that are available here: https://spdx.org/licenses/.

Alternatives

Other libraries addressing concurrency/parallelism:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].