27.10.2014 Views

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Solutions</strong> to Chapter 18 | Threads <strong>and</strong> Locks<br />

39<br />

40 int main() {<br />

41 /* foo is any class defined for which we want singleton access */<br />

42 Foo* singleton_foo = Singleton::Instance();<br />

43 return 0;<br />

44 }<br />

The general method to make a program thread safe is to lock shared resources whenever<br />

write permission is given. This way, if one thread is modifying <strong>the</strong> resource, o<strong>the</strong>r threads<br />

can not modify it.<br />

CareerCup.com<br />

2 6 0

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!