Fixed example in MessageLoop::ReleaseSoon comment

The previous version could cause race condition if for whatever reason ReleaseSoon finished releasing on another thread before we got to "foo = NULL"

BUG=

Review URL: https://codereview.chromium.org/301943003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273879 0039d316-1c4b-4281-b951-d872f2087c98
parent 1b63d607
...@@ -208,15 +208,16 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate { ...@@ -208,15 +208,16 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
// released on a particular thread. // released on a particular thread.
// //
// A common pattern is to manually increment the object's reference count // A common pattern is to manually increment the object's reference count
// (AddRef), issue a ReleaseSoon, then clear the pointer. The reference count // (AddRef), clear the pointer, then issue a ReleaseSoon. The reference count
// is incremented manually to ensure clearing the pointer does not trigger a // is incremented manually to ensure clearing the pointer does not trigger a
// delete and to account for the upcoming decrement (ReleaseSoon). For // delete and to account for the upcoming decrement (ReleaseSoon). For
// example: // example:
// //
// scoped_refptr<Foo> foo = ... // scoped_refptr<Foo> foo = ...
// foo.AddRef(); // foo->AddRef();
// message_loop->ReleaseSoon(foo.get()); // Foo* raw_foo = foo.get();
// foo = NULL; // foo = NULL;
// message_loop->ReleaseSoon(raw_foo);
// //
// NOTE: This method may be called on any thread. The object will be // NOTE: This method may be called on any thread. The object will be
// released (and thus possibly deleted) on the thread that executes // released (and thus possibly deleted) on the thread that executes
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment