socksify-ruby icon indicating copy to clipboard operation
socksify-ruby copied to clipboard

Use thread local variables instead of class variables

Open astro opened this issue 10 years ago • 6 comments

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

astro avatar May 28 '15 14:05 astro

@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".

musybite avatar Jul 31 '15 17:07 musybite

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

jakemack avatar Aug 05 '15 19:08 jakemack

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

jakemack avatar Aug 12 '15 17:08 jakemack

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.

ojab avatar Dec 08 '15 10:12 ojab

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.

musybite avatar Mar 13 '18 19:03 musybite

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

rajsahae avatar Apr 16 '20 22:04 rajsahae