add original source

This commit is contained in:
Bo Wang
2014-04-22 21:54:16 -04:00
parent f7a05be5e1
commit 6e45d14431
128 changed files with 5726 additions and 0 deletions

28
source/listing_3.11.cpp Normal file
View File

@@ -0,0 +1,28 @@
#include <memory>
#include <mutex>
struct some_resource
{
void do_something()
{}
};
std::shared_ptr<some_resource> resource_ptr;
std::mutex resource_mutex;
void foo()
{
std::unique_lock<std::mutex> lk(resource_mutex);
if(!resource_ptr)
{
resource_ptr.reset(new some_resource);
}
lk.unlock();
resource_ptr->do_something();
}
int main()
{
foo();
}