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 groups 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 nitcorn nitcorn nitcorn->pthreads nlp nlp nlp->pthreads popcorn popcorn popcorn->pthreads popcorn->nitcorn 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 github github github->nitcorn github... ... github...->github popcorn... ... popcorn...->popcorn

Parents

package core

core

Nit common library of core classes and methods

Children

package actors

actors

Nit Actor Model
package app

app

app.nit, a framework for portable applications
package nitcorn

nitcorn

Lightweight framework for Web applications development
package nlp

nlp

Nit wrapper for Stanford CoreNLP
package popcorn

popcorn

Popcorn

Descendants

package android

android

Android platform support and APIs
package egl

egl

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

gamnit

Portable game and multimedia framework for Nit
package github

github

Nit wrapper for Github API
package glesv2

glesv2

OpenGL graphics rendering library for embedded systems, version 2.0
package ios

ios

iOS support for app.nit
package linux

linux

Implementation of app.nit for the Linux platform