C CRITICAL_SECTION in windows2 min read

CRITICAL_SECTION (MSDN) in Windows can be used for thread synchronization. Essentially you can create a variable and limit it’s ownership to one thread at a time.  Something like this CRITICAL_SECTION cs; volatile long counter = 0; int main(){ InitializeCriticalSection(&cs); //Create threads and run thread_func //….. //….. } void thread_func (){ //Get ownership of counter EnterCriticalSection(&cs); […]

C TCP Server in Windows – Thread per connection2 min read

A simple TCP server in C (windows). It works in a “thread per connection” way. Note- I don’t know what I am doing. #include <winsock.h> #include <stdio.h> #include <string.h> #include <sys/types.h> #define PORT 50001 //Function that threads run static DWORD __stdcall func(int s); int main() { //Dont ask just put it in there WSADATA wsaData; […]