Threads in MS Windows(Cont / threadsum c * int addem(int count) /* To compile: >cl threadsum.c /MT*/ nt 1. sum #include <stdio sum=0 #include <stdlib # include <process. h> for(i=1; i<=count; 1++) int addem (int) printf(" The value of i is %d\n,1); Int main( fflush(stdout) beginthread((void ()(void)addem, 0, (void *)5); sum +=1 addem(5); return 0 printf("The sum of i is %d n', sum) fflush(stdout) return 0 6
6 Threads in MS Windows (Cont.) int addem(int count) { int i, sum; sum = 0; for(i = 1; i <= count; i++) { printf(“The value of i is %d\n”, i); fflush(stdout); sum += i; } printf( “The sum of i is %d \n”, sum); fflush(stdout); return 0; } /* threadsum.c */ /* To compile: > cl threadsum.c /MT */ #include <stdio.h> #include <stdlib.h> #include <process.h> int addem(int); int main() { _beginthread( (void (*)(void())addem, 0, (void *)5); addem(5); return 0; }
Threads in Ms Windows(Cont y ca Visual Studio. NET 2003 Command Prompt □ D: \hkbu\teaching \comp2330\2009>cl threadsum.c /MT Copyright (C) Microsoft Corporation 1984-2002. All rights reserved or80x86 Microsoft (R)32-bit C/C++ Optimizing Compiler Version 13.10.6030 f Microsoft (R> Incremental Linker Version 7.10.6030 opyright (c) Microsoft Corporation. All rights reserved out: threadsum exe threads. obj D: \ hkbu \teaching \comp2330\ 2009>threadsum D: \hkbu \teaching\comp2330\2009>threadsum The value of i is 1 he value of i is 1 The value of i is 1 The value of i The value of i is 2 he value of i is/2 The value of i i The value of i is 3 f lue of i is 2 he value of i is 3 The value of i is3 The value of i is 4 The value of i is 4 The value of i is 5 The value of The value of i is 5 The sum is 15 The value of i is 5 is 15 The sum is 15 The sum is 15 D: \hkbu \teaching \comp2330\2009> D: \hkbu \teaching \comp2330\2009>
7 Threads in MS Windows (Cont.)
Server Design Issues Connectionless vs. connection-oriented - UDP vS TCP -Reliability issue? tCP wins - Support of broadcast or multicast? UDP wins -Real time applications? UDP may win Client and server must use the same protocol
8 Server Design Issues • Connectionless vs. connection-oriented —UDP vs. TCP —Reliability issue? TCP wins. —Support of broadcast or multicast? UDP wins. —Real time applications? UDP may win. • Client and server must use the same protocol