Re: [Boost-users] Thread-safe smart pointers, hashtables without locking

Thanks. I will plan on pursuing it, then.
I was somewhat aware of memory ordering and especially compiler reordering, but I need to take another look at it and find the proper set of macros for use in non-kernel code since volatile does not (yet) guarantee hardware behavior between processors.
Actually, I was not concerned with incrementing the ref count. The flip-gate-count-thing solves, I believe, the problem of reference counts not being up to date all the time. I realize that I still have to prove this, but I do not think it is hard. What worries me more is whether the smart pointer has one or two fields in it, because this affects whether readers find an incomplete/ broken smart pointer as they whiz by. With a single pointer field in it, the load and store are atomic.
shared_ptr has two pointers in it, (one to the shared count, one for the pointer) whereas intrusive_ptr has a single pointer in it (since the count is internal to the referenced class). This means that the shallow bits of shared_ptr are not atomically initialized, whereas those of intrusive_ptr are. An obvious way to solve this would be to make shared_ptr contain a single pointer to a wrapper class that contains both the shared count and a shared pointer, but this adds an unacceptable level of indirection to basic pointer operations.
I will have to adjust my language. I tend to use uncertain language both because I consider my knowledge incomplete and because of the lack of a generic standard that guarantees behavior, i.e. the fact that different Linux kernel architectures need different memory barriers, etc. is demonstration of the uncertainty of a general C solution. If I can rely on something like what the Linux kernel relies on, it should not be scary. Behavior needs to be guaranteed on supported platforms, and other platforms need to be detected and fail to compile lock-free or revert to a locking fallback implementation, etc. Ray Whitmer

Ray, with regards to resizing the hash map: You may want to look at a technique called "Linear Hashing". It may be a nicer way to implement growth for highly concurrent hashes. Regards, Tom
participants (2)
-
Ray Whitmer
-
Tomas Puverle