Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add EEP 39: Scoped Group Leaders

  • Loading branch information...
commit 184bea6f25a4979ad643522a558e1aac1a4d6f93 1 parent 68a1e5a
RaimoNiskanen RaimoNiskanen authored

Showing 1 changed file with 169 additions and 0 deletions. Show diff stats Hide diff stats

  1. +169 0 eeps/eep-0039.md
169 eeps/eep-0039.md
Source Rendered
... ... @@ -0,0 +1,169 @@
  1 + Author: Yurii Rashkovskii <yrashk(at)gmail(dot)com>
  2 + Status: Draft
  3 + Type: Standards Track
  4 + Erlang-Version: R15A
  5 + Created: 2-Jul-2011
  6 + Post-History: 2-Jul-2011
  7 +****
  8 +EEP 39: Scoped Group Leaders
  9 +----
  10 +
  11 +
  12 +
  13 +Abstract
  14 +========
  15 +
  16 +Scoped group leaders is an extension of the existing group leader
  17 +mechanism that allows one to use the group leader mechanism beyond
  18 +its original intent (which is I/O only).
  19 +
  20 +Specification
  21 +=============
  22 +
  23 +Every process is given a "dictionary" of group leaders, with one
  24 +`io` group leader defined by default, representing the only group
  25 +leader that exists currently in Erlang. Every process created is
  26 +given a copy of the dictionary exactly as before.
  27 +
  28 +Two new functions have been added to the `erlang` module.
  29 +
  30 +Firstly, scoped group leader retrieval:
  31 +
  32 + erlang:group_leader(Scope :: atom()) -> 'undefined' | pid()
  33 +
  34 +This function retrieves the group leader for the scope `Scope`. Existing
  35 +argument-free function `erlang:group_leader/0` is now implemented as
  36 +
  37 + erlang:group_leader(io)
  38 +
  39 +Secondly, scoped group leader setup:
  40 +
  41 + erlang:group_leader(Scope :: atom(), GroupLeader :: pid(),
  42 + Proc :: pid()) -> true.
  43 +
  44 +This function sets the group leader for scope the `Scope` to the `GroupLeader`
  45 +for a process `Proc`. The existing function `erlang:group_leader/2` is
  46 +now implemented as
  47 +
  48 + erlang:group_leader(io, GroupLeader, Proc)
  49 +
  50 +Process information available through `erlang:process_info/1` and
  51 +`erlang:process_info/2` has been extended with a new key, `group_leaders`.
  52 +It contains a proplist of group leaders associated with the process given.
  53 +The list will at the very least contain the tuple `{io, <0.24.0>}`
  54 +Note: this group leader is currently the default one in every single process.
  55 +
  56 +Distribution mechanism(s) get extended to support these scoped group leaders
  57 +as well, so processes spawned on remote nodes get the whole list of group
  58 +leaders copied.
  59 +
  60 +Example
  61 +-------
  62 +
  63 +In this example, we'll set a group leader for the scope of `test`
  64 +and we'll retrieve it from the current and the child processes.
  65 +Also, we'll retrieve the `io` scoped group leader using both the
  66 +original and the new API:
  67 +
  68 + 1> erlang:group_leader(test, self(), self()).
  69 + true
  70 + 2> erlang:group_leader().
  71 + <0.24.0>
  72 + 3> erlang:group_leader(io).
  73 + <0.24.0>
  74 + 4> erlang:group_leader(test).
  75 + <0.31.0>
  76 + 5> spawn(fun() -> io:format("~p~n",[erlang:group_leader()]) end), ok.
  77 + <0.24.0>
  78 + ok
  79 + 6> spawn(fun() -> io:format("~p~n",[erlang:group_leader(io)]) end), ok.
  80 + <0.24.0>
  81 + ok
  82 + 7> spawn(fun() -> io:format("~p~n",[erlang:group_leader(test)]) end), ok.
  83 + <0.31.0>
  84 + ok
  85 + 8> spawn(fun() -> io:format("~p~n",[erlang:process_info(self())]) end), ok.
  86 + [{current_function,{erl_eval,do_apply,5}},
  87 + {initial_call,{erlang,apply,2}},
  88 + {status,running},
  89 + {message_queue_len,0},
  90 + {messages,[]},
  91 + {links,[]},
  92 + {dictionary,[]},
  93 + {trap_exit,false},
  94 + {error_handler,error_handler},
  95 + {priority,normal},
  96 + {group_leader,<0.24.0>},
  97 + {group_leaders,[{test,<0.31.0>},{io,<0.24.0>}]},
  98 + {total_heap_size,233},
  99 + {heap_size,233},
  100 + {stack_size,24},
  101 + {reductions,93},
  102 + {garbage_collection,[{min_bin_vheap_size,46368},
  103 + {min_heap_size,233},
  104 + {fullsweep_after,65535},
  105 + {minor_gcs,0}]},
  106 + {suspending,[]}]
  107 + ok
  108 +
  109 +
  110 +Motivation
  111 +==========
  112 +
  113 +The I/O system is not the only domain where the concept of group leaders
  114 +comes in handy. Implicit configurations, security groups and many other
  115 +problems could benefit from being able to extend the standard group leader
  116 +mechanism.
  117 +
  118 +One of the potential uses of this technique could be an extension of the
  119 +I/O leader paradigm into Web Development, with a `web` group leader
  120 +represented as an HTTP connection, WebSocket, or Session. With this simple
  121 +approach one can use the same technique used by I/O primitives to allow
  122 +transparent and/or multiplexed access to other HTTP communication channels,
  123 +within either local or remote processes.
  124 +
  125 +
  126 +Rationale
  127 +=========
  128 +
  129 +We have chosen to extend the existing API instead of introducing a new one
  130 +simply because we believe this concept to be a natural evolution of the
  131 +group leaders concept with which people are already familiar.
  132 +
  133 +
  134 +Backwards Compatibility
  135 +=======================
  136 +
  137 +The proposed changes keep existing API's intact and only provide some new
  138 +functions for this pre-described functionality. While this change maintains
  139 +backwards compatibility, the existing behaviour's are not altered and newly
  140 +introduced behaviour's are fashioned to mimic existing ones.
  141 +
  142 +The Proplist returned by `erlang:process_info/1` has all pre-existing keys
  143 +unmodified and features, with the addition of a new key called `group_leaders`.
  144 +In the unlikely event that code exists which relies on a specific set of keys
  145 +used in this proplist, no backwards compatibility issues should exist.
  146 +
  147 +Reference Implementation
  148 +========================
  149 +
  150 +There is no reference implementation at this point. However, a proof
  151 +of concept implementation is [available][1].
  152 +
  153 +[1]: https://github.com/spawngrid/otp/tree/group_leader_scope
  154 +
  155 +
  156 +Copyright
  157 +=========
  158 +
  159 +This document has been placed in the public domain.
  160 +
  161 +
  162 +
  163 +[EmacsVar]: <> "Local Variables:"
  164 +[EmacsVar]: <> "mode: indented-text"
  165 +[EmacsVar]: <> "indent-tabs-mode: nil"
  166 +[EmacsVar]: <> "sentence-end-double-space: t"
  167 +[EmacsVar]: <> "fill-column: 70"
  168 +[EmacsVar]: <> "coding: utf-8"
  169 +[EmacsVar]: <> "End:"

0 comments on commit 184bea6

Please sign in to comment.
Something went wrong with that request. Please try again.