peterhellberg / hashids.rb

A small Ruby gem to generate YouTube-like hashes from one or many numbers. Use hashids when you do not want to expose your database ids to the user.
http://www.hashids.org/ruby/
MIT License
977 stars 46 forks source link

Is this thread-safe? #11

Closed FranklinYu closed 8 years ago

FranklinYu commented 8 years ago

It is not mentioned in README. For example, if I initialize a hashids instance at startup, and have several concurrent threads encoding and decoding with the instance, would there be race condition? In other words, will the #encode, #decode, #encode_hex and #decode_hex modify the hashids instance?

peterhellberg commented 8 years ago

None of the core data structures in Ruby are thread safe, but as long as you don’t modify the internal state of the instance after creation then I believe that it is safe. I have only used it under MRI (Where we have a GIL)

You are welcome to verify this using JRuby if you want :)

FranklinYu commented 8 years ago

Yes, I also believe it safe if I do not modify it; but I would like to know, in your implementation, whether the four method you provide will modify it. So it is not about my usage, but about the detailed implementation; sure I can check myself by reading the implementation line by line, but I would appreciate it if you know it.

peterhellberg commented 8 years ago

I believe that they are safe, but it was a long time since I wrote the code so you’ll better check for yourself. I’m closing this issue now, but you are welcome to open it again if you find an issue.