Java 응용 프로그램을 C#에 이식하는 부분은 C#에서 동기화 된 메시지 버퍼를 구현하는 것입니다. 동기화를 통해 스레드가 메시지를 쓰고 읽는 것이 안전해야한다는 것을 의미합니다.C#의 동기화 된 메서드
자바에서는 synchronized
메서드와 wait()
및 notifyAll()
메서드를 사용하여 해결할 수 있습니다.
예 :
public class MessageBuffer {
// Shared resources up here
public MessageBuffer() {
// Initiating the shared resources
}
public synchronized void post(Object obj) {
// Do stuff
wait();
// Do more stuff
notifyAll();
// Do even more stuff
}
public synchronized Object fetch() {
// Do stuff
wait();
// Do more stuff
notifyAll();
// Do even more stuff and return the object
}
}
나는 C#에서 비슷한 일을 달성 할 수 있는가?
관련 항목 : http://stackoverflow.com/questions/541194/c-sharp-version-of-javas-synchronized-keyword – sshow
@stigok 관련 없음, 중복 됨 –
중복되지 않음, wait() 및 notifyAll() – Dimme