GithubHelp home page GithubHelp logo

gcproc's Introduction

GCproc

This library implements garbage-collected processes by (ab)using garbage collection of NIF resources.

Big thanks to Tony Rogvall who did all the hard parts in http://github.com/tonyrog/resource project.

Please note that node will be garbage collected along with the resource, hence it may take some short time before it's terminated due to way BEAM GC works.

Notes:

  1. work only with SMP enabled!
  2. garbage collection works well only locally, since NIF resource reference counting is per-node

Usage

Example:

1> results(0). %% make sure shell doesn't cache results
20
2> ok = application:start(gcproc).
ok
3> G = gcproc:spawn(fun() -> receive ok -> ok end end).
{gcproc,<0.40.0>,{resource,143010032,<<>>}}
4> is_process_alive(pid(0,40,0)).
true %% process is still running
5> f(). %% forget all shell bindings
ok
6> is_process_alive(pid(0,40,0)).
false %% process is not running anymore!

Sending message

9> G = gcproc:spawn(fun() -> receive done -> io:format("Receive works!") end, receive ok -> ok end end).
{gcproc,<0.49.0>,{resource,143008592,<<>>}}
10> G:send(done). %% equivalent to "G:pid() ! done"
Receive works!
done
11> is_process_alive(pid(0,49,0)).
true
12> f().
ok
13> is_process_alive(pid(0,49,0)).
false

gcproc's People

Contributors

gleber 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.