Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Funny way how to get thread specific id
Funny way how to get thread specific id [message #7642] Fri, 12 January 2007 11:07 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Sometimes it could be useful to test quickly for thread specific id.

For example, if you are incrementing reference count, it seems to be possible to store thread specific id somewhere and then perform non-atomic increment if they match. (Disclaimer: MAYBE. I do not say it is really possible, it is just my current research subject).

Today I have found a nice and simple way how to obtain such id:

__thread int x;

&x is your ID Wink

It is pretty fast too, because TLS pointers are stored in register (in fact, in gs segment on x86).

Mirek
Re: Funny way how to get thread specific id [message #7655 is a reply to message #7642] Fri, 12 January 2007 23:46 Go to previous messageGo to next message
gprentice is currently offline  gprentice
Messages: 260
Registered: November 2005
Location: New Zealand
Experienced Member
That reminds me of this (non thread-safe) code and bug in VC7. I don't have the latest version of VC to see if it's been fixed.

[edit] URL didn't seem to work, try this
http://tinyurl.com/y4otk6

Graeme

[Updated on: Fri, 12 January 2007 23:50]

Report message to a moderator

Re: Funny way how to get thread specific id [message #7656 is a reply to message #7655] Sat, 13 January 2007 00:08 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Yes, I have noticed this behavior too... Since them I simply do not rely on statics inside templates to be unique...

(In this case, planned possible use was within single .cpp file).

Mirek

[Updated on: Sat, 13 January 2007 00:08]

Report message to a moderator

Previous Topic: Interesting advantage of using indices instead of iterators
Next Topic: Linear sorted array vs. tree
Goto Forum:
  


Current Time: Wed Apr 24 08:28:44 CEST 2024

Total time taken to generate the page: 0.01722 seconds