資源簡(jiǎn)介
icarnegie ssd6 exercise6 答案

代碼片段和文件信息
/*
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:?“?< return?1;
}
return?0;
}
#endif
void?calc(void?*?param)?{
//?Old?algorithm?fails?under?certain?OS‘s?on?mobile?processors
//?becaus
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????475??2010-01-26?11:12??ex6\part1\graph\answers.txt
?????文件???????3163??2002-10-11?11:49??ex6\part1\graph\clsData.cls
?????文件???????1586??2002-10-11?09:09??ex6\part1\graph\clsThread.cls
?????文件??????14243??2002-10-29?09:55??ex6\part1\graph\frmGraph.frm
?????文件??????49152??2002-10-29?09:57??ex6\part1\graph\graph.exe
?????文件????????802??2002-10-29?09:56??ex6\part1\graph\graph.vbp
?????文件???????2061??2010-01-26?01:47??ex6\part1\graph\output.out
?????文件??????20543??2010-01-16?11:45??ex6\part1\graph.zip
?????文件????????125??2010-01-26?01:44??ex6\part1\Timestamp\run.cmd
?????文件?????????32??2010-01-16?14:50??ex6\part1\Timestamp\simplerun.cmd
?????文件??????10388??2008-05-02?21:24??ex6\part1\Timestamp\test.cpp
?????文件?????184320??2005-08-17?11:31??ex6\part1\Timestamp\Timestamp.exe
?????文件???????4069??2008-05-02?21:27??ex6\part1\Timestamp\Timestamp.vcproj
?????文件???????2126??2002-10-04?14:12??ex6\part1\Timestamp\tsc.c
?????文件???????1158??2002-08-03?19:19??ex6\part1\Timestamp\tsc.h
?????文件??????92755??2010-01-16?11:45??ex6\part1\Timestamp.zip
?????文件???????6244??2010-01-26?12:55??ex6\part2\threadedclient\Debug\BuildLog.htm
?????文件?????????67??2010-01-26?12:55??ex6\part2\threadedclient\Debug\mt.dep
?????文件??????????3??2010-01-26?12:41??ex6\part2\threadedclient\Debug\run.cmd
?????文件??????60416??2010-01-26?12:55??ex6\part2\threadedclient\Debug\tclient.exe
?????文件????????621??2010-01-26?12:55??ex6\part2\threadedclient\Debug\tclient.exe.intermediate.manifest
?????文件?????437960??2010-01-26?12:55??ex6\part2\threadedclient\Debug\tclient.ilk
?????文件?????601088??2010-01-26?12:55??ex6\part2\threadedclient\Debug\tclient.pdb
?????文件??????66217??2010-01-26?12:55??ex6\part2\threadedclient\Debug\ThreadedClient.obj
?????文件?????461824??2010-01-26?12:55??ex6\part2\threadedclient\Debug\vc90.idb
?????文件?????266240??2010-01-26?12:55??ex6\part2\threadedclient\Debug\vc90.pdb
?????文件??????59904??2008-05-02?21:02??ex6\part2\threadedclient\sclient.exe
?????文件???????1241??2005-03-25?18:09??ex6\part2\threadedclient\servers.h
?????文件?????100221??2008-05-02?20:36??ex6\part2\threadedclient\servers.obj
?????文件??????59904??2008-05-02?21:02??ex6\part2\threadedclient\tclient.exe
............此處省略16個(gè)文件信息
- 上一篇:ARW報(bào)告指南
- 下一篇:葉片泵數(shù)模
評(píng)論
共有 條評(píng)論