|
Boost : |
From: John Ky (newhoggy_at_[hidden])
Date: 2006-06-16 06:52:54
Basically, I want to know if the following code is guaranteed to not crash:
boost::shared_ptr<int> shared_int;
// thread 1
while (true) {
if (rand() < MAX_RAND / 2) {
shared_int = boost::shared_ptr<int>(new int(rand()));
} else {
shared_int.reset();
}
}
// thread 2
while (true) {
boost::shared_ptr<int> my_int = shared_int;
if (my_int.get()) {
printf("%d\n", *my_int);
}
}
On 6/16/06, John Ky <newhoggy_at_[hidden]> wrote:
> Hi,
>
> What does "undefined" mean in the shared_ptr documentation about thread safety?
>
> http://www.boost.org/libs/smart_ptr/shared_ptr.htm#ThreadSafety
>
> I'd like to be able to do simultaneous read/writes, but on a global
> shared pointer without locking, but I'm unsure of the consequences.
>
> -John
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk