Skip to content

Instantly share code, notes, and snippets.

@evanmcc
Created September 21, 2014 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanmcc/244c8482cec8fdb4b7eb to your computer and use it in GitHub Desktop.
Save evanmcc/244c8482cec8fdb4b7eb to your computer and use it in GitHub Desktop.
notes on implementing queue bounds

steps

erl_send

  • in bif.c
  • calls do_send
  • otherwise handles the erlang side of things, returning the right thing, bumping reductions, etc.

send3

  • in bif.c
  • also calls do send and seems to have some overlap with erl_send
  • can likely do this without understanding the difference fully

do_send

  • in bif.c
  • resolves the reciever
    • internal pid
    • external pid
    • atom
    • internal port
    • remote send tuple
  • send goto target
    • jumped to by most internal stuff after resolve
    • calls erts_send_message, then unlocks??

erts_send_message

  • in erl_message.c
  • allocate a blank message
  • if not rec proc pending exit
    • move in_queue to private queue ????
    • add message to private queue
    • missed an if this is only if sender == reciever
  • else
    • call queue_message

support

erlang support functions

process_flag(bounded_queue, unbounded)

  • return a pid’s message queues to normal

process_flag(bounded_queue, N :: integer())

  • the default action on setting a limit is ‘drop’

process_flag(bounded_queue, {Action, N :: integer()})

  • where Action: drop | exception | reciever_dies

process_info(bounded_queue) -> unbounded | {Action, N}

concerns

  • in a number of cases, we’re not going to be able to deliver on the promise that ‘exception’ makes, should we even allow it as an option?

todo [7/7]

  • [x] figure out how to kill a process
    • details in bif.c exit_2
    • see also erts_send_exit_signal
  • [X] make the reciever actually die
  • [X] add tests
  • [X] add process_info support
  • [X] add process_flag support
  • [X] add documentation
  • [X] make sure all of this works on ports as well?
    • I think that the saner thing is to make this an error when applied to a port
    • in which case, we should make sure that none of these checks are applied when the message is sent to a port.
    • I think we’re OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment