icarnegie ssd6 exercise6 答案
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 475 2010-01-26 11:12 ex6part1graphanswers.txt
文件 3163 2002-10-11 11:49 ex6part1graphclsData.cls
文件 1586 2002-10-11 09:09 ex6part1graphclsThread.cls
文件 14243 2002-10-29 09:55 ex6part1graphfrmGraph.frm
文件 49152 2002-10-29 09:57 ex6part1graphgraph.exe
文件 802 2002-10-29 09:56 ex6part1graphgraph.vbp
文件 2061 2010-01-26 01:47 ex6part1graphoutput.out
文件 20543 2010-01-16 11:45 ex6part1graph.zip
文件 125 2010-01-26 01:44 ex6part1Timestamp
un.cmd
文件 32 2010-01-16 14:50 ex6part1Timestampsimplerun.cmd
文件 10388 2008-05-02 21:24 ex6part1Timestamp est.cpp
文件 184320 2005-08-17 11:31 ex6part1TimestampTimestamp.exe
文件 4069 2008-05-02 21:27 ex6part1TimestampTimestamp.vcproj
文件 2126 2002-10-04 14:12 ex6part1Timestamp sc.c
文件 1158 2002-08-03 19:19 ex6part1Timestamp sc.h
文件 92755 2010-01-16 11:45 ex6part1Timestamp.zip
文件 6244 2010-01-26 12:55 ex6part2 hreadedclientDebugBuildLog.htm
文件 67 2010-01-26 12:55 ex6part2 hreadedclientDebugmt.dep
文件 3 2010-01-26 12:41 ex6part2 hreadedclientDebug
un.cmd
文件 60416 2010-01-26 12:55 ex6part2 hreadedclientDebug client.exe
文件 621 2010-01-26 12:55 ex6part2 hreadedclientDebug client.exe.intermediate.manifest
文件 437960 2010-01-26 12:55 ex6part2 hreadedclientDebug client.ilk
文件 601088 2010-01-26 12:55 ex6part2 hreadedclientDebug client.pdb
文件 66217 2010-01-26 12:55 ex6part2 hreadedclientDebugThreadedClient.obj
文件 461824 2010-01-26 12:55 ex6part2 hreadedclientDebugvc90.idb
文件 266240 2010-01-26 12:55 ex6part2 hreadedclientDebugvc90.pdb
文件 59904 2008-05-02 21:02 ex6part2 hreadedclientsclient.exe
文件 1241 2005-03-25 18:09 ex6part2 hreadedclientservers.h
文件 100221 2008-05-02 20:36 ex6part2 hreadedclientservers.obj
文件 59904 2008-05-02 21:02 ex6part2 hreadedclient client.exe
............此处省略16个文件信息
/*
test.cpp
A test program for the timestamp library.
*/
#include
using namespace std;
#include
#include
#include
#include
#include
#include se.h>
#include “tsc.h“
/*
void spin( int thread_number int iteration_count
int report_mode int threshold )
Create a table of readings from the timestamp counter
and print a report to stdout.
report_mode should be either REP_DUMP in which case all
the entries should be output or REP_SWITCH in which case
only the switches should be noted. In the latter case
threshold will be used as a threshold for what constitutes
a switch unless it‘s 0 in which case the minimum threshold
will be calculated.
*/
void spin( int process_number
int iteration_count
int report_mode
int report_count
int threshold );
/*
int make_thread( ... )
Create a thread to run spin() passing it the given arguments
and return 0. Or fail and return 1.
*/
int make_thread( int process_number
int iteration_count
int report_mode
int report_count
int threshold );
/*
Cruft needed to get threads working
*/
#ifdef _MSC_VER
#include
#include se.h>
#include
/*
semaphore synchronization primitive.
*/
typedef HANDLE sem_t;
CRITICAL_SECTION output_lock;
/*
Initialise a semaphore.
*/
void sem_init( sem_t *sem int init int max ) {
*sem = CreateSemaphore( NULL init max NULL );
}
/*
Wait for a semaphore (the P() operation).
*/
void sem_wait( sem_t *sem ) {
WaitForSingleobject( *sem INFINITE );
}
/*
Release a semaphore (the V() operation ).
*/
void sem_release( sem_t *sem ) {
ReleaseSemaphore( *sem 1 0 );
}
/*
The semaphore for threads returning.
*/
sem_t semaphore;
signed __int64 gstart;
struct spin_args {
spin_args( int p int i int d int r int t ) {
process_number = p;
iteration_count = i;
report_type = d;
report_count = r;
threshold = t;
}
int process_number;
int iteration_count;
int report_type;
int report_count;
int threshold;
};
/*
This is the function we want _beginthread to spawn at.
*/
void __cdecl _msc_spin( void *param ) {
spin_args args = *((spin_args *) param);
delete (spin_args *) param;
spin( args.process_number args.iteration_count
args.report_type args.report_count args.threshold );
sem_release( &semaphore );
}
/*
Create the thread.
*/
int make_thread( int p int i int o int r int t ) {
spin_args *s = new spin_args( p i o r t );
sem_wait( &semaphore );
if (_beginthread( &_msc_spin 0 s ) == -1) {
sem_release( &semaphore );
cerr << “...failed: “ << errno << endl;
return 1;
}
return 0;
}
#endif
void calc(void * param) {
// Old algorithm fails under certain OS‘s on mobile processors
// becaus
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 475 2010-01-26 11:12 ex6part1graphanswers.txt
文件 3163 2002-10-11 11:49 ex6part1graphclsData.cls
文件 1586 2002-10-11 09:09 ex6part1graphclsThread.cls
文件 14243 2002-10-29 09:55 ex6part1graphfrmGraph.frm
文件 49152 2002-10-29 09:57 ex6part1graphgraph.exe
文件 802 2002-10-29 09:56 ex6part1graphgraph.vbp
文件 2061 2010-01-26 01:47 ex6part1graphoutput.out
文件 20543 2010-01-16 11:45 ex6part1graph.zip
文件 125 2010-01-26 01:44 ex6part1Timestamp
un.cmd
文件 32 2010-01-16 14:50 ex6part1Timestampsimplerun.cmd
文件 10388 2008-05-02 21:24 ex6part1Timestamp est.cpp
文件 184320 2005-08-17 11:31 ex6part1TimestampTimestamp.exe
文件 4069 2008-05-02 21:27 ex6part1TimestampTimestamp.vcproj
文件 2126 2002-10-04 14:12 ex6part1Timestamp sc.c
文件 1158 2002-08-03 19:19 ex6part1Timestamp sc.h
文件 92755 2010-01-16 11:45 ex6part1Timestamp.zip
文件 6244 2010-01-26 12:55 ex6part2 hreadedclientDebugBuildLog.htm
文件 67 2010-01-26 12:55 ex6part2 hreadedclientDebugmt.dep
文件 3 2010-01-26 12:41 ex6part2 hreadedclientDebug
un.cmd
文件 60416 2010-01-26 12:55 ex6part2 hreadedclientDebug client.exe
文件 621 2010-01-26 12:55 ex6part2 hreadedclientDebug client.exe.intermediate.manifest
文件 437960 2010-01-26 12:55 ex6part2 hreadedclientDebug client.ilk
文件 601088 2010-01-26 12:55 ex6part2 hreadedclientDebug client.pdb
文件 66217 2010-01-26 12:55 ex6part2 hreadedclientDebugThreadedClient.obj
文件 461824 2010-01-26 12:55 ex6part2 hreadedclientDebugvc90.idb
文件 266240 2010-01-26 12:55 ex6part2 hreadedclientDebugvc90.pdb
文件 59904 2008-05-02 21:02 ex6part2 hreadedclientsclient.exe
文件 1241 2005-03-25 18:09 ex6part2 hreadedclientservers.h
文件 100221 2008-05-02 20:36 ex6part2 hreadedclientservers.obj
文件 59904 2008-05-02 21:02 ex6part2 hreadedclient client.exe
............此处省略16个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)