January 2020
Intermediate to advanced
532 pages
13h 31m
English
The singleton pattern is used to create a single instance of an object and reuse it from anywhere. A singleton object is typically constructed when the application starts, or it can be created lazily on the first use of the object. An interesting requirement for the singleton pattern arises for multithreaded applications because the instantiation of the singleton object must happen only once. It can be a challenge if the object creation function is called lazily from many threads.
Suppose that we want to create a singleton called AppKey that is used for encryption in the application:
# AppKey contains an app id and encryption keystruct AppKey appid::String value::UInt128end
Initially, we may be tempted to use a global ...
Read now
Unlock full access