How are the object_ids generated/assigned to objects?

P

Pavel Smerk

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.
 
A

Alex Young

Pavel said:
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.
 
A

ara.t.howard

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
 
T

Timothy Goddard

Treat it as undefined. No two objects live at the same time will have
the same object id. That is the only guarantee.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top