프로그래밍
-
[소켓프로그래밍] 6. 스레드 동기화 (임계 영역, 이벤트)윈도우 소켓 프로그래밍 2024. 8. 26. 15:58
이 게시글은 'TCP/IP 윈도우 소켓 프로그래밍 (김선우 저, 한빛아카데미)'를 공부한 내용을 기반으로 작성됨 멀티스레드를 이용하는 경우, 두 개 이상의 스레드가 공유 데이터에 접근하면 여러 문제가 발생할 수 있다. 예를 들어 공유 변수 int money = 1000이 존재한다고 할 때, 스레드 #1이 money에 2000을 더하여 money = 3000이 되었다고 해보자. 이때 스레드 #2가 money = 3000이 되기 전에 이미 money를 read 해놓은 상태라고 해보자. 스레드 #2 입장에서는 money = 1000이기 때문에, 만약 이에 3000을 더해준다면 money = 4000이 된다. 이러한 상황이 발생하면 스레드 #1의 명령이 무시되는 것이므로, 오류로 볼 수 있다. 이러한 멀티스레드..
-
[소켓프로그래밍] 1. 소켓 생성과 닫기, 바이트 정렬윈도우 소켓 프로그래밍 2024. 8. 16. 17:30
이 게시글은 'TCP/IP 윈도우 소켓 프로그래밍 (김선우 저, 한빛아카데미)'를 공부한 내용을 기반으로 작성됨 #define _WINSOCK_DEPRECATED_NO_WARNINGS // winsock c4996 처리#include #include #include using namespace std;#pragma comment(lib,"ws2_32.lib") // ws2_32.lib 라이브러리를 링크void err_quit(LPCTSTR msg){ LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, WSAGetLastError(), MAKELANGID(LANG_NEUTRA..