Boost logo

Boost :

From: Miki Jovanovic (miki_at_[hidden])
Date: 2000-03-03 17:01:02


"borgerding, mark a." <marka-_at_[hidden]> wrote:
> > - Also huge issue, you protect the left, right pointers, however,
you
> > do not protect ptr. In your setup, left, right AND ptr, must
> > be changed
> > together, or inconsistency will occur. Examine ptr1 = ptr2 and ptr1
=
> > ptr3 executing in parallel.
>
> I don't think this is an issue. Even with primitive pointers, the
above
> case for primitive pointers would have undefined results. ptr1 could
end up
> with the value of ptr2, ptr3, or something else entirely could happen
> (crash?). The same thing is true for linked_ptr. As far as
synchronization
> issues, the case for dumb pointers basically boils down to the same
thing as
> if they were dumb pointers.

Check this execution path...

thread1 thread2
------- -------
ptr1 = ptr2
if ptr != other.get()
curptr = ptr
ptr = other.get()
         * * * context switch * * *
                           ptr1 = ptr3
                           if ptr != other.get()
                           curptr = ptr
                           ptr = other.get()
                           leave_list (returns false)
                           return *this
         * * * context switch * * *
leave_list (returns false)
return *this

In this example, ptr1 will have the value of ptr3, but will be in the
linked list for ptr2. Big problem. You have a reference count out of
sync, and can cause the object pointed to by ptr1 to be deleted while
ptr1 still points to it.

> > - Sorry for not compiling your code, but will it compile with a
static
> > variable declaration without the corresponding .cpp file where it is
> > defined?
>
> It is declared static (and defined) within the scope of the function.
 As
> long as that function does not somehow end up with multiple
definitions, I
> think it should be okay.

I always get confused with compilation units... Header file is not a
compilation unit, it has to be included. Static variables have to be
defined in a compilation unit, no matter where the declaration lies. If
included in several .cpp's how does linker know which one... Very
confusing. I'll just have to trust you on this one :-)

Cheers,

Miki.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk