Skip to main content
gamedev.net
🔒 Locked

ref count, thread id's

Started by vesoljc 1 reply 200+ views
Original Post
vesoljc
vesoljc
here we go again i''m still "working" on shared data. each data object has a ref counter and a status bitset. what i wanna do is add support for MT. nothing complicated, just when object is being shared it is shifted into "shared" state (so it uses internal locking). now, to find out if "the user", who got (aquired) a data object reference causes the shift from not_shared to shared state, we need some kind of a thread id. would work something like this: - give first reference to a user, query the user for thread id, remember the id - give second/other reference, again query the user for thread id, if id differs from that one we remembered, switch the state however, this creates some problems. we need to maintain a database of ref2thread_ids. so, i''m looking for a way on how to store these "items" an example: say we have one shared data object X, five threads (a,b,c,d,e), each thread has 10 "users". now it would be a waste of resources, to keep a thread ID for every reference, since some references come from the same thread. what kind of a container do u recommend?
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com
Zipster
Zipster
Sounds like a job for a map. Your key would be the thread id, and your value would be the reference count for that thread. If a thread is already in the map when it wants another reference, then add to its existing reference count. When the reference count for any particular thread reaches 0, remove it from the map. When there is only one element in the map (ie. only one thread), then you don't have sharing, otherwise you do.

You could either use std::map or std::hash_map (non-standard, but works well in this case).

[edited by - Zipster on April 19, 2004 2:26:25 PM]
vesoljc
vesoljc
that simple, huh?

tnx
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.