SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Downloaden Sie, um offline zu lesen
Singleton Pattern


sdk159147@gmail.com
• , ( )
!
object: 0x40012a
~
!
object: 0x40012a
~
!
object: 0x40012a
~
N !
object: 0x40012a
~
object: 0x40012a
object: 0x40012a
object: 0x40012a
object: 0x40012a
N
.
.
.
.
.
.
N
!
?
?
• 

•
Singleton (1)
• private


•
static mInstance 

• data instance
Singleton (2)
•
getInstance() 

• Static
• s1, s2, s3 add()
3 ->


•
S1
add()
Data: 1
object
0x40012a
• s1, s2, s3 add()
3 ->


•
S1 S2
add() add()
Data: 1 Data: 2
object
0x40012a
object
0x40012a
• s1, s2, s3 add()
3 ->


•
S1 S2 S3
add() add() add()
Data: 1 Data: 2 Data: 3
object
0x40012a
object
0x40012a
object
0x40012a
Thread1 Thread2 Thread3
getInstance() getInstance() getInstance()
object: 0x400120
Thread1 Thread2 Thread3
getInstance() getInstance() getInstance()
nullptr !
!
object: 0x400120
Thread1
object: 0x400120
Thread2 Thread3
getInstance() getInstance() getInstance()
nullptr !
!
~
object: 0x400120
Thread1
object: 0x400120
Thread2
object: 0x400128
Thread3
getInstance() getInstance() getInstance()
nullptr !
!
~
nullptr?
! !
???
?
~
Thread1
Thread2
Thread3
mInstance = nullptr
Thread1
mInstance = nullptr
Thread2
mInstance = nullptr
Thread3
?
~
Thread1
Thread2
Thread3
mInstance = nullptr
Thread1
mInstance = nullptr
Thread2
mInstance = nullptr
Thread3
?
~
Thread1
Thread2
Thread3
mInstance = nullptr
Thread1
mInstance = nullptr
Thread2
mInstance = nullptr
Thread3
?
~
Thread1
Thread2
Thread3
mInstance = 0x400120
Thread1
mInstance = nullptr
Thread2
mInstance = nullptr
Thread3
?
~
Thread1
Thread2
Thread3
mInstance = 0x400120
Thread1
mInstance = 0x400120
Thread2
mInstance = nullptr
Thread3
?
~
Thread1
Thread3
mInstance = 0x400120
Thread1
mInstance = 0x400120
Thread2
mInstance = 0x400128
Thread3
Thread2
!
getInstance()+8 cmp mInstance, 0x0
getInstance()+12 jne getInstance()+20
getInstance()+16 mInstance = new Singleton()
getInstance()+20 ret
• if cmp Jmp instructure
.
!
getInstance()+8 cmp mInstance, 0x0
getInstance()+12 jne getInstance()+20
getInstance()+16 mInstance = new Singleton()
getInstance()+20 ret
Thread1
Thread3
Thread2
mInstance = nullptr
Thread1
getInstance()+8 cmp mInstance, 0x0
getInstance()+12 jne getInstance()+20
getInstance()+16 mInstance = new Singleton()
getInstance()+20 ret
Thread1(getInstance()+8)
Thread3
Thread2
mInstance = nullptr
jne instructure
getInstance()+8 cmp mInstance, 0x0
getInstance()+12 jne getInstance()+20
getInstance()+16 mInstance = new Singleton()
getInstance()+20 ret
Thread1(getInstance()+12)
Thread3
Thread2
mInstance = nullptr
mInstance nullptr
Thread3 cmp
getInstance()+8 cmp mInstance, 0x0
getInstance()+12 jne getInstance()+20
getInstance()+16 mInstance = new Singleton()
getInstance()+20 ret
Thread1(getInstance()+12)
Thread3(getInstance()+12)
Thread2
mInstance = nullptr
Thread3
Thread1
getInstance()+8 cmp mInstance, 0x0
getInstance()+12 jne getInstance()+20
getInstance()+16 mInstance = new Singleton()
getInstance()+20 ret
Thread1(getInstance()+16)
Thread2
mInstance = 0x400120
Thread3(getInstance()+12)
mInstance
Thread3
getInstance()+8 cmp mInstance, 0x0
getInstance()+12 jne getInstance()+20
getInstance()+16 mInstance = new Singleton()
getInstance()+20 ret
Thread1(getInstance()+20)
Thread2
Thread3(getInstance()+16)
mInstance = 0x400120
Thread1
mInstance = 0x400128
Thread3
• race condition
mutex thread
.

• ! Mutex !
DCL
(Double Checked Locking)
• Locking , if . 

-> lock
DCL
(Double Checked Locking)
• instance , lock .
DCL
(Double Checked Locking)
• Locking thread-safe .
instance .
object: 0x40012a
object: 0x40012a
object: 0x40012a
object: 0x40012a
object: 0x40012a
Only One Object, Same Instance!
~

Weitere ähnliche Inhalte

Mehr von YoungSu Son

오픈소스 Jedis 리펙토링 하기 (redis java 라이브러리)
오픈소스 Jedis 리펙토링 하기 (redis java 라이브러리) 오픈소스 Jedis 리펙토링 하기 (redis java 라이브러리)
오픈소스 Jedis 리펙토링 하기 (redis java 라이브러리)
YoungSu Son
 

Mehr von YoungSu Son (20)

실전 서버 부하테스트 노하우
실전 서버 부하테스트 노하우 실전 서버 부하테스트 노하우
실전 서버 부하테스트 노하우
 
생성 패턴 (강태우 - 소마에 10기)
생성 패턴 (강태우 - 소마에 10기) 생성 패턴 (강태우 - 소마에 10기)
생성 패턴 (강태우 - 소마에 10기)
 
초보 개발자/학생들을 위한 오픈소스 트랜드
초보 개발자/학생들을 위한 오픈소스 트랜드 초보 개발자/학생들을 위한 오픈소스 트랜드
초보 개발자/학생들을 위한 오픈소스 트랜드
 
DevOps 오픈소스 트랜드 (클라우드, 모바일 중심)
DevOps 오픈소스 트랜드 (클라우드, 모바일 중심) DevOps 오픈소스 트랜드 (클라우드, 모바일 중심)
DevOps 오픈소스 트랜드 (클라우드, 모바일 중심)
 
모바일 앱 성능 분석 방법 101 (Mobile Application Performance Analysis Methodology 101)
모바일 앱 성능 분석 방법 101 (Mobile Application Performance Analysis Methodology 101) 모바일 앱 성능 분석 방법 101 (Mobile Application Performance Analysis Methodology 101)
모바일 앱 성능 분석 방법 101 (Mobile Application Performance Analysis Methodology 101)
 
DevOps 시대가 요구하는 품질확보 방법
DevOps 시대가 요구하는 품질확보 방법 DevOps 시대가 요구하는 품질확보 방법
DevOps 시대가 요구하는 품질확보 방법
 
클라우드 환경에서 알아야할 성능 이야기
클라우드 환경에서 알아야할 성능 이야기클라우드 환경에서 알아야할 성능 이야기
클라우드 환경에서 알아야할 성능 이야기
 
Android 성능 지표와 Oreo 의 개선사항
Android 성능 지표와  Oreo 의 개선사항 Android 성능 지표와  Oreo 의 개선사항
Android 성능 지표와 Oreo 의 개선사항
 
안드로이드 Oreo의 변화와 모바일 앱/플랫폼의 적합한 성능 측정 방법
안드로이드 Oreo의 변화와  모바일 앱/플랫폼의 적합한 성능 측정 방법안드로이드 Oreo의 변화와  모바일 앱/플랫폼의 적합한 성능 측정 방법
안드로이드 Oreo의 변화와 모바일 앱/플랫폼의 적합한 성능 측정 방법
 
클라우드 & 모바일 환경에서 알아야 할 성능 품질 이야기
클라우드 & 모바일 환경에서 알아야 할 성능 품질 이야기클라우드 & 모바일 환경에서 알아야 할 성능 품질 이야기
클라우드 & 모바일 환경에서 알아야 할 성능 품질 이야기
 
SW 아키텍처 분석방법
SW 아키텍처 분석방법 SW 아키텍처 분석방법
SW 아키텍처 분석방법
 
[NEXT] Android Profiler 사용법
[NEXT] Android Profiler 사용법 [NEXT] Android Profiler 사용법
[NEXT] Android Profiler 사용법
 
Android Studio 개발 셋팅 + Genymotion
Android Studio 개발 셋팅 + GenymotionAndroid Studio 개발 셋팅 + Genymotion
Android Studio 개발 셋팅 + Genymotion
 
FullStack 개발자 만들기 과정 소개 (Android + MEAN Stack + Redis 다루기)
FullStack 개발자 만들기 과정 소개  (Android + MEAN Stack + Redis 다루기) FullStack 개발자 만들기 과정 소개  (Android + MEAN Stack + Redis 다루기)
FullStack 개발자 만들기 과정 소개 (Android + MEAN Stack + Redis 다루기)
 
[NEXT] Flask 로 Restful API 서버 만들기
[NEXT] Flask 로 Restful API 서버 만들기 [NEXT] Flask 로 Restful API 서버 만들기
[NEXT] Flask 로 Restful API 서버 만들기
 
[NEXT] GCM을 이용한 게시글 자동 갱신
[NEXT] GCM을 이용한 게시글 자동 갱신[NEXT] GCM을 이용한 게시글 자동 갱신
[NEXT] GCM을 이용한 게시글 자동 갱신
 
[NEXT] Andorid에 MVC 패턴 적용하기
[NEXT] Andorid에 MVC 패턴 적용하기[NEXT] Andorid에 MVC 패턴 적용하기
[NEXT] Andorid에 MVC 패턴 적용하기
 
[NEXT] 화면 재갱신이 되는 안드로이드 앱 만들기 - 네트워크에 독립하는 구조로 변경
[NEXT] 화면 재갱신이 되는 안드로이드 앱 만들기 - 네트워크에 독립하는 구조로 변경[NEXT] 화면 재갱신이 되는 안드로이드 앱 만들기 - 네트워크에 독립하는 구조로 변경
[NEXT] 화면 재갱신이 되는 안드로이드 앱 만들기 - 네트워크에 독립하는 구조로 변경
 
오픈소스 Jedis 리펙토링 하기 (redis java 라이브러리)
오픈소스 Jedis 리펙토링 하기 (redis java 라이브러리) 오픈소스 Jedis 리펙토링 하기 (redis java 라이브러리)
오픈소스 Jedis 리펙토링 하기 (redis java 라이브러리)
 
URQA 삼성 컨퍼런스 발표
URQA 삼성 컨퍼런스 발표 URQA 삼성 컨퍼런스 발표
URQA 삼성 컨퍼런스 발표
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Singleton 패턴 (김진영 - EVA, 소마에 10기)