資源簡(jiǎn)介
SSD6-EXERCISE6 分?jǐn)?shù)比較高

代碼片段和文件信息
/*
ThreadedClient.cpp
A?threaded?database?client.
?*/
#include?
#include?“servers.h“
#ifdef?_MSC_VER
#include?
#include?se.h>
#include?
typedef?__int64?INT64_T;
typedef?unsigned?__int64?UINT64_T;
typedef?LONGLONG?time_ms_t;
//The?get?personal?infomation?function
void?__cdecl?threadPersonFunc(void?*);
//The?get?account?infomation?function
void?__cdecl?threadAccountFunc(void?*);
//The?personal?ptr
Personal?*pers;
//The?accountInfo?ptr
AccountInfo?*acct;
time_ms_t?getTimeInMilliseconds()?{
SYSTEMTIME?stime;
GetSystemTime(?&stime?);
FILETIME?ftime;
LARGE_INTEGER?time;
SystemTimeToFileTime(?&stime?&ftime?); /*?if?this?fails...?*/
time.HighPart?=?ftime.dwHighDateTime;
time.LowPart?=?ftime.dwLowDateTime;
/*?FileTime?is?in?100ns?intervals?since?1/1/1601?*/
return?time.QuadPart?/?10000;
}
#endif
/*
ostream?&operator?<<(?ostream?&out?string?*str?)?{
Send?a?string?to?an?output?stream.
?*/
ostream?&operator<<(ostream?&out?string?*str)?{
if?(str)
return?out?<data();
else
return?out;
}
/*
????ostream?&?operator<(?ostream?&out?INT64_T?num?)
Print?a?64-bit?unsigned?integer?to?the?given?output?stream.
??*/
ostream?&operator<<(?ostream?&out?INT64_T?snum?)?{
#define?_OSTR_LL_LEN?21
if?(snum)?{
char?buffer[_OSTR_LL_LEN];
int?i?=?_OSTR_LL_LEN?-?1;
????????UINT64_T?num;
if?(snum?0)?num?=?-snum;?else?num?=?snum;
buffer[i]?=?‘\0‘;
while?(num)?{
buffer[--i]?=?(‘0‘?+?(int)?(num?%?10));
num?/=?10;
}
if?(snum?0)?buffer[--i]?=?‘-‘;
return?out?< }else?return?out?<‘0‘;
}
/*
int?main(?int?argc?char?*argv[]
You?should?modify?this?function?to?use?threads.
?*/
int?main(?int?argc?char?*argv[]?)?{
if?(argc?!=?2)?{
cerr?<“usage:?“?< exit(1);
}
int?account?=?atoi(?argv[1]?);
HANDLE?thread[2];
time_ms_t?start?=?getTimeInMilliseconds();
cout?<“Retrieving...“;
cout.flush();
//call?_beginthread?function?to?get?a?thread
thread[0]?=?(HANDLE)?_beginthread(?threadPersonFunc?0?&account?);
thread[1]?=?(HANDLE)?_beginthread(?threadAccountFunc?0?&account?);
//if?call?failed?then?exit
????if?(thread[0]?==?(HANDLE)?-1L?||?thread[1]?==?(HANDLE)?-1L)?{
cerr?<“Couldn‘t?create?thread!“?< exit(1);
????}
else?{
? WaitForMultipleobjects(?2?thread?true?INFINITE);
????}
time_ms_t?end?=?getTimeInMilliseconds();
cout?<“done?(“?<
if?(pers)?{
cout?<FirstName?<“?“
<LastName?< cout?<Address?< cout?<“Balance:?“?<Balance?<“?“?<Pending
<“?pending?“?<Share?<“?share“?<
delete?pers;
delete?acct;
}else?cout?<“No?client?matches?that?account?number“?<
return?0;
}
//The?threadPersonFunc?function?which?is?cal
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????696??2008-12-11?20:51??ex6\answers.txt
?????文件????????402??2008-12-11?20:12??ex6\output.out
?????文件???????3370??2009-05-19?11:59??ex6\ThreadedClient.cpp
?????目錄??????????0??2008-12-11?20:52??ex6
-----------?---------??----------?-----??----
?????????????????4468????????????????????4
評(píng)論
共有 條評(píng)論