Hello,
assume some multithreaded application, thread1 starts and finishes, then
thread2 starts — how is the possibility that these two threads will
have the same object_id? On what it depends?
Thanks,
P.
Hello,
assume some multithreaded application, thread1 starts and finishes, then
thread2 starts — how is the possibility that these two threads will
have the same object_id? On what it depends?
Thanks,
P.
Pavel S. wrote:
Hello,
assume some multithreaded application, thread1 starts and finishes, then
thread2 starts — how is the possibility that these two threads will
have the same object_id? On what it depends?
If the first thread has stopped and been garbage collected, its
object_id will be available for reuse, and it is perfectly possible for
another thread to get it assigned on creation.
On Sat, 26 Aug 2006, Pavel S. wrote:
Hello,
assume some multithreaded application, thread1 starts and finishes, then
thread2 starts — how is the possibility that these two threads will have
the same object_id? On what it depends?Thanks,
P.
interesting question!
harp:~ > cat a.rb
h = {}
loop{ tid = Thread.new{}.object_id; (warn h.size.to_s and
h.delete(tid)) if h[tid]; h[tid] = true }
harp:~ > ruby a.rb 2>&1|head
4344
4344
5428
5428
5428
5428
6510
6510
6510
6510
looks like they recycle every few thousand threads - depending on how
long the
threads run of course.
cheers.
-a
Treat it as undefined. No two objects live at the same time will have
the same object id. That is the only guarantee.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs