Replies: 3 comments 2 replies
-
Q) 멀티 쓰레드 프로그래밍 작성 시 유의점
Q) 동기화 구현을 위한 하드웨어적 해결 방법Q) volatile 키워드 의미
Singleton 구현 방법 중 Lazy Initialization + Synchronization(지연 초기화 + 동기화) 방식으로 멀티스레딩의 문제를 해결하기 위해 사용한 synchronized로 인한 성능의 문제를 해결하는 방법으로 Lazy Holder 방식과, DCL 방식이 있고 public class Singleton {
private volatile static Singleton3 uniqueInstance;
private Singleton3() {}
public static Singleton3 getInstance() {
if (uniqueInstance == null) {
synchronized (Singleton3.class) {
if (uniqueInstance == null) {
uniqueInstance = new Singleton3();
}
}
}
return uniqueInstance;
}
}
Q) 싱글코어가 아니라 멀티코어라면, 어떻게 동기화가 이뤄질까요?
싱글 코어 멀티스레드에서 동기화
멀티코어에서의 동기화
캐시 일관성 문제
가시성 (Visibility) 문제
참고 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
❓ 멀티 쓰레드 프로그래밍 작성 시 유의점🌱 [ 동시성 문제 주의 ]
❓ 동기화를 구현하기 위한 하드웨어적 해결 방법에 대해 설명해주세요.🌱 [ TAS 연산 ( Test - And - Set ) ] boolean test_and_set(boolean *lock) { boolean old_value = *lock; *lock = true; return old_value; }
🌱 [ CAS 연산 ( Compare - And - Swap ) ] private static int incrementAndGet(AtomicInteger atomicInteger) { int getValue; boolean result; do { getValue = atomicInteger.get(); sleep(100); log("getValue : " + getValue); result = atomicInteger.compareAndSet(getValue, getValue + 1); log("result : " + result); }while (!result); return getValue + 1; }
❓ volatile 키워드는 어떤 의미가 있나요?
[ 캐시 메모리 사용 이유 ]
[ 언제 캐시 값이 메모리에 반영 되나요? / 언제 메인 메모리 값을 캐시에서 읽나요? ]
[ 메모리 가시성 문제를 어떻게 해결 하나요? ]
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions