POSIX Threads support

The threads can be manipulated and synchronized using the classes Thread, Mutex and Barrier.

This group also provides two optional modules with thread-safe collections:

  • redef_collections redefines existing collection to make them thread-safe. This incures a small overhead in all usage of the redefined collections.
  • concurrent_collections intro new thread-safe collections.

Theses services are implemented using the POSIX threads.

You can also use the is threaded annotation on methods, which makes them run on their own thread. Methods with self calls are not supported.

A method or function annotated with is threaded has its return value changed during compilation. You will get a subclass of Thread, even if there wasn't a return value before. You can know if the threaded method is done with the is_done boolean from Thread. A call to the join method will block the execution until the threaded method is done, or immediatly return if it's already done. join will return an object typed with the orginial return type, or null if there wasn't.

Known limitations:

  • Most services from the Nit library are not thread-safe. You must manage your own mutex to avoid conflicts on shared data.
  • FFI's global references are not thread-safe.

For more information:

  • See: man pthreads
  • See: examples/concurrent_array_and_barrier.nit
  • See: ̀ examples/threaded_example.nit`

All subgroups and modules

module concurrent_collections

pthreads :: concurrent_collections

Introduces thread-safe concurrent collections
module extra

pthreads :: extra

Offers some POSIX threads services that are not available on all platforms
module pthreads

pthreads :: pthreads

Main POSIX threads support and intro the classes Thread, Mutex and Barrier
module redef_collections

pthreads :: redef_collections

Redef some basic collections to be thread-safe
module threadpool

pthreads :: threadpool

Introduces a minimal ThreadPool implementation using Tasks
package_diagram pthreads\> pthreads core core pthreads\>->core actors actors actors->pthreads\> app app app->pthreads\> libevent libevent libevent->pthreads\> nitcorn nitcorn nitcorn->pthreads\> nitcorn->libevent nlp nlp nlp->pthreads\> popcorn popcorn popcorn->pthreads\> pthreads\>examples\> examples pthreads\>examples\>->pthreads\> android android android->app gamnit gamnit gamnit->app ios ios ios->app linux linux linux->app android... ... android...->android gamnit... ... gamnit...->gamnit ios... ... ios...->ios linux... ... linux...->linux nitcorn... ... nitcorn...->nitcorn github github github->popcorn github... ... github...->github

Ancestors

group codecs

core > codecs

Group module for all codec-related manipulations
group collection

core > collection

This module define several collection classes.
group text

core > text

All the classes and methods related to the manipulation of text entities

Parents

group core

core

Nit common library of core classes and methods

Children

group actors

actors

Nit Actor Model
group app

app

app.nit, a framework for portable applications
group libevent

libevent

Low-level wrapper around the libevent library to manage events on file descriptors
group nitcorn

nitcorn

Lightweight framework for Web applications development
group nlp

nlp

Nit wrapper for Stanford CoreNLP
group popcorn

popcorn

Popcorn

Descendants

group agent_simulation

actors > examples > agent_simulation

a "Framework" to make Multi-Agent Simulations in Nit
group android

android

Android platform support and APIs
group bundle

android > bundle

A mapping class of String to various value types used by the
group depth

gamnit > depth

gamnit depth, a framework to create portable 3D games in Nit.
group egl

egl

Interface between rendering APIs (OpenGL, OpenGL ES, etc.) and the native windowing system.
group examples

app > examples

group examples

nlp > examples

group examples

ios > examples

group fannkuchredux

actors > examples > fannkuchredux

Example implemented from "The computer Language Benchmarks Game" - Fannkuch-Redux
group flat

gamnit > flat

Simple API for 2D games, built around Sprite and App::update
group gamnit

gamnit

Portable game and multimedia framework for Nit
group github

github

Nit wrapper for Github API
group glesv2

glesv2

OpenGL graphics rendering library for embedded systems, version 2.0
group intent

android > intent

Services allowing to launch activities and start/stop services using
group ios

ios

iOS support for app.nit
group linux

linux

Implementation of app.nit for the Linux platform
group mandelbrot

actors > examples > mandelbrot

Example implemented from "The computer Language Benchmarks Game" - Mandelbrot
group notification

android > notification

Services to show notification in the Android status bar
group service

android > service

Android service support for app.nit centered around the class Service
group shared_preferences

android > shared_preferences

Services allowing to save and load datas to internal android device
group simple

actors > examples > simple

A very simple example of the actor model
group src

android > examples > src

group src

nitcorn > examples > src

group ui

ios > ui

Implementation of app::ui for iOS
group ui

android > ui

Views and services to use the Android native user interface
group virtual_gamepad

gamnit > virtual_gamepad

Virtual gamepad mapped to keyboard keys for quick and dirty mobile support