multithreaded_sockets_programming

multithreaded_sockets_programming - IEG 4180 Network...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
IEG 4180 IEG 4180 Network Software Design and Programming Network Software Design and Programming Multithreaded Sockets Programming Multithreaded Sockets Programming
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
IEG4180: Network Software Design and Programming - Multithreaded Sockets Programming 2 Copyright Jack Y. B. Lee All Rights Reserved Contents • 1. Introduction • 2. Multithreaded Concurrent Server • 3. Race Condition • 4. Data Corruption • 5. Mutual Exclusion • 6. Thread Management • 7. Thread Synchronization • 8. Thread Scheduling • 9. Case Study - Threaded NetProbe
Background image of page 2
IEG4180: Network Software Design and Programming - Multithreaded Sockets Programming 3 Copyright Jack Y. B. Lee All Rights Reserved 1. Introduction • Process and Threads Item Thread Process Code No Yes Data No Yes Resource No Yes Heap No Yes Stack Yes No CPU Context Yes No When a process is created, the system creates a primary thread. Process Primary Thread
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
IEG4180: Network Software Design and Programming - Multithreaded Sockets Programming 4 Copyright Jack Y. B. Lee All Rights Reserved 1. Introduction • Process and Threads ± A process can create another process (e.g., fork() in Unix) • The child process has its own copy of data, heap, etc. • An expensive way to create another thread. • The system call fork() is not supported in Windows. fork() Parent Process fork() returns xyz Thread Process ID: xyz fork() returns 0
Background image of page 4
IEG4180: Network Software Design and Programming - Multithreaded Sockets Programming 5 Copyright Jack Y. B. Lee All Rights Reserved 1. Introduction • Process and Threads ± A process can create another thread: HANDLE CreateThread( LPSECURITY_ATTRIBUTES lpThreadAttributes , // pointer to thread security attributes DWORD dwStackSize , // initial thread stack size, in bytes LPTHREAD_START_ROUTINE lpStartAddress , // pointer to thread function LPVOID lpParameter , // argument for new thread DWORD dwCreationFlags , // creation flags LPDWORD lpThreadId // pointer to returned thread identifier ); DWORD WINAPI YourThreadFunc (LPVOID lpvThreadParm); CreateThread( ) YourThreadFunc( ) { while (!ExitFlag) { . . . } } Windows Kernel . . . Primary Thread New Thread
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
IEG4180: Network Software Design and Programming - Multithreaded Sockets Programming 6 Copyright Jack Y. B. Lee All Rights Reserved 1. Introduction • Process and Threads ± Threads in the same process share all data: ± But each thread has its own stack: • Maximum stack size per thread is 1MB (virtual address space). • The maximum stack size can be configured during linking, or afterwards by editing the program EXE file directly. Process Primary Thread Add. Thread A Add. Thread B Data Segment Heap Segment sockets
Background image of page 6
IEG4180: Network Software Design and Programming - Multithreaded Sockets Programming 7 Copyright Jack Y. B. Lee All Rights Reserved 2. Multithreaded Concurrent Server • Program Flow for Blocking I/O: socket(s) bind(s) listen(s) ns=accept(s) closesocket(s) send/recv(ns) closesocket(ns) CreateThread() Primary Thread Thread for New Connection The Application Process DWORD ClientThread( ) { while (!ExitFlag) { // send/recv(ns) } closesocket(ns); }
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 38

multithreaded_sockets_programming - IEG 4180 Network...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online