• 大小: 2KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: 其他
  • 标签: SSD6EX6  

资源简介

SSD6-EXERCISE6 分数比较高

资源截图

代码片段和文件信息



/*
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 << str->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 << buffer + i;
}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: “ << argv[0] << “ [account_number]“ << endl;
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!“ << endl;
exit(1);
    }
else {
  WaitForMultipleobjects( 2 thread true INFINITE);
    }

time_ms_t end = getTimeInMilliseconds();
cout << “done (“ << end - start << “ms)“ << endl;

if (pers) {
cout << account << “: “ << pers->FirstName << “ “
<< pers->LastName << endl;
cout << pers->Address << endl;
cout << “Balance: “ << acct->Balance << “ “ << acct->Pending
<< “ pending “ << acct->Share << “ share“ << endl;

delete pers;
delete acct;
}else cout << “No client matches that account number“ << endl;

return 0;
}

//The threadPersonFunc function which is cal

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        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


评论

共有 条评论

相关资源