astro / socksify-ruby

Redirect any TCP connection initiated by a Ruby script through a SOCKS5 proxy
http://socksify.rubyforge.org/
Other
163 stars 77 forks source link

Use thread local variables instead of class variables #22

Open astro opened 9 years ago

astro commented 9 years ago

Got this by mail, leaving it here for the new maintainer, @musybite

musybite commented 9 years ago

@jakemack thanks, your contribution is greatly appreciated!

I wonder what was specific reason to prefer thread_variable_get/thread_variable_set over plain []/[]=? IMO all those class variables making more sense in fiber-local context than in "shared-between-all-fibers-thread-local-context".

jakemack commented 9 years ago

That's a good point, I believe you are right.

jakemack commented 9 years ago

@musybite Is this a change you'd want me to make and submit or is it quick and easy enough for you to implement?

ojab commented 8 years ago

Actually there is a use case for thread local variables: Celluloid runs actors in separate threads, but different calls to actors are run in different Fibers. Testcase shows that fibers are different and variables are lost:

I, [2015-12-08T10:34:21.428386 #19221]  INFO -- : : thread = '#<Celluloid::Thread:0x007f827b1b8500>' 'second', fiber = '#<Fiber:0x007f8279a3d9e8>' ''
I, [2015-12-08T10:34:21.428514 #19221]  INFO -- : : thread = '#<Celluloid::Thread:0x007f8279a26180>' 'first', fiber = '#<Fiber:0x007f8279a3d1f0>' ''
I, [2015-12-08T10:34:21.429111 #19221]  INFO -- : : thread = '#<Celluloid::Thread:0x007f827b1b8500>' 'second', fiber = '#<Fiber:0x007f827b863b20>' ''
I, [2015-12-08T10:34:21.429280 #19221]  INFO -- : : thread = '#<Celluloid::Thread:0x007f8279a26180>' 'first', fiber = '#<Fiber:0x007f827b8631e8>' ''

So at least for this/my usecase fiber-local variables are no-go.

musybite commented 6 years ago

Sorry for long response time :) So, we have at least couple of valid use-cases for thread-local variables and i see no real reason for fiber-local variables. I guess i'll adapt @jakemack's MR.

rajsahae commented 4 years ago

I'm curious if this will ever be merged? @musybite are you still actively maintaining this gem?