Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Thread-local keys are easy to collide with #117

Closed
halorgium opened this Issue · 6 comments

2 participants

@halorgium
Owner

InternalPool [1] uses thread[:queue] and assumes that no-one else will use this.
TaskFiber and TaskThread use :actor, :task and :mailbox.

I recommend changing these to something including celluloid.

@halorgium
Owner

Note: this only occurs with TaskThread.

require 'celluloid'

class ClearQueue
  include Celluloid
  task_class TaskThread

  def break
    Thread.current[:queue] = nil
  end
end

cq = ClearQueue.new
cq.break
cq.break
@tarcieri
Owner

Good point, at the very least these should probably be :celluloid_actor, :celluloid_queue, etc.

For actors themselves I could probably subclass Thread and add the relevant fields as attributes of the current thread, so actors could be built on Celluloid::Threads and let you do Thread.current.actor without all of the logic to determine whether or not you're in a thread context like the current implementation uses.

That would give a lot cleaner API, IMO

@tarcieri tarcieri closed this issue from a commit
@tarcieri tarcieri Namespace thread locals (fixes #117)
This namespaces the four thread local names that Celluloid used
previously:

* :actor
* :mailbox
* :task
* :queue

...with celluloid_ on the front so as to avoid collisions:

* :celluloid_actor
* :celluloid_mailbox
* :celluloid_task
* :celluloid_queue
2db76eb
@tarcieri tarcieri closed this in 2db76eb
@tarcieri tarcieri referenced this issue from a commit
@tarcieri tarcieri Revert "Namespace thread locals (fixes #117)"
This reverts commit 2db76eb.

This is incompatible with Celluloid::IO, etc
c448598
@halorgium halorgium reopened this
@halorgium
Owner

Would it make sense to add the subclass impl so that the old Thread-local keys could be maintained for a version or two?

@tarcieri
Owner

Nah, I think I'll just save this for 0.13.x when I can coordinate the change across all projects at the same time

@halorgium
Owner

Rgr.

@tarcieri
Owner

This is fixed in master, although ideally I think I'd like to use the "new" thread local API from Ruby 2.0. A backport should be available in the thread_safe gem soon.

@tarcieri tarcieri closed this
@shadoi shadoi referenced this issue from a commit in shadoi/celluloid
@tarcieri tarcieri Namespace thread locals (fixes #117)
This namespaces the four thread local names that Celluloid used
previously:

* :actor
* :mailbox
* :task
* :queue

...with celluloid_ on the front so as to avoid collisions:

* :celluloid_actor
* :celluloid_mailbox
* :celluloid_task
* :celluloid_queue
867f183
@shadoi shadoi referenced this issue from a commit in shadoi/celluloid
@tarcieri tarcieri Revert "Namespace thread locals (fixes #117)"
This reverts commit 2db76eb.

This is incompatible with Celluloid::IO, etc
0850265
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.