e2b错误以及308错误是段皮wp8.1GDR1版本升级出现的新错误,目前e2b错误可以通过刷机至wp8,再重新升级至8.1解决,但是所需时间较多,而308错误则不好解决。你要是急的话可以刷机,不急请等微软的解决方案
满意请采纳哗燃慎,不懂请追问
package day17.gobangimport java.util.Arrays
public class GoBangGame {
public static final char BLANK='*'
public static final char BLACK='@'
public static final char WHITE='O'
public static final int MAX = 16
private static final int COUNT = 5
//棋盘
private char[][] board
public GoBangGame() {
}
//开始游戏
public void start() {
board = new char[MAX][MAX]
//把二维数组蚂洞都填充‘*’
for(char[] ary: board){
Arrays.fill(ary, BLANK)
}
}
public char[][] getChessBoard(){
return board
}
public void addBlack(int x, int y) throws ChessExistException{
//@
//char blank = '*'
//System.out.println( x +"," + y + ":" + board[y][x] + "," + BLANK)
if(board[y][x] == BLANK){// x, y 位置上必须是空的才可以添棋子
board[y][x] = BLACK
return
}
throw new ChessExistException("已经有棋子了!")
}
public void addWhite(int x, int y)
throws ChessExistException{
if(board[y][x] == BLANK){// x, y 位置上必须是空的才可以添棋子
board[y][x] = WHITE
return
}
throw new ChessExistException("已经有棋子了!")
}
//chess 棋子:'@'/'O'
public boolean winOnY(char chess, int x, int y){
//先找到y方向第一个不是 blank的棋子
int top = y
while(true){
if(y==0 || board[y-1][x]!=chess){
//如果y已经是闷厅枯棋盘的边缘, 或者的前一个不是chess
//就不再继续查找了
break
}
y--
top = y
}
//向回统计所有chess的个数,如果是COUNT个就赢了
int count = 0
y = top
while(true){
if(y==MAX || board[y][x]!=chess){
//如果找到头 或者 下一个子不是chess 就不再继续统计了
break
}
count++
y++
}
return count==COUNT
}
//chess 棋子:'@'/'O'
public boolean winOnX(char chess, int x, int y){
//先找到x方向第一个不是 blank的棋子
int top = x
while(true){
if(x==0 || board[y][x-1]!=chess){
//如果x已经是棋盘的边缘, 或者的前一伏空个不是chess
//就不再继续查找了
break
}
x--
top = x
}
//向回统计所有chess的个数,如果是COUNT个就赢了
int count = 0
x = top
while(true){
if(x==MAX || board[y][x]!=chess){
//如果找到头 或者 下一个子不是chess 就不再继续统计了
break
}
count++
x++
}
return count==COUNT
}
//chess 棋子:'@'/'O'
public boolean winOnXY(char chess, int x, int y){
//先找MAX向第一个不是 blank的棋子
int top = y
int left = x
while(true){
if(x==0 || y==0 || board[y-1][x-1]!=chess){
//如果x已经是棋盘的边缘, 或者的前一个不是chess
//就不再继续查找了
break
}
x--
y--
top = y
left=x
}
//向回统计所有chess的个数,如果是COUNT个就赢了
int count = 0
x = left
y = top
while(true){
if(x==MAX || y==MAX || board[y][x]!=chess){
//如果找到头 或者 下一个子不是chess 就不再继续统计了
break
}
count++
x++
y++
}
return count==COUNT
}
//chess 棋子:'@'/'O'
public boolean winOnYX(char chess, int x, int y){
//先找到x方向第一个不是 blank的棋子
int top = y
int left = x
while(true){
if(x==MAX-1 || y==0 || board[y-1][x+1]!=chess){
//如果x已经是棋盘的边缘, 或者的前一个不是chess
//就不再继续查找了
break
}
x++
y--
top = y
left=x
}
//向回统计所有chess的个数,如果是COUNT个就赢了
int count = 0
x = left
y = top
while(true){
if(x==0 || y==MAX || board[y][x]!=chess){
//如果找到头 或者 下一个子不是chess 就不再继续统计了
break
}
count++
x--
y++
}
return count==COUNT
}
public boolean whiteIsWin(int x, int y) {
//在任何一个方向上赢了,都算赢
return winOnY(WHITE, x, y) ||
winOnX(WHITE, x, y) ||
winOnXY(WHITE, x, y) ||
winOnYX(WHITE, x, y)
}
public boolean blackIsWin(int x, int y) {
return winOnY(BLACK, x, y) ||
winOnX(BLACK, x, y) ||
winOnXY(BLACK, x, y) ||
winOnYX(BLACK, x, y)
}
}
// 最近正好也关注这个问题,下面是我的实现,主要参考自windows 内核实验教程#include "windows.h"
#include <conio.h>
#include <stdlib.h>
#include <fstream.h>
#include <io.h>
#include <string.h>
#include <stdio.h>
#include "winbase.h"
#define READER 'R' // 读者
#define WRITER 'W' // 写者
#define INTE_PER_SEC1000 // 每秒时钟中断的数目
#define MAX_THREAD_NUM 64 // 最大线程数
int nReaderCnt = 0 // 读者计数
int nWriterCnt = 0 // 写者计数
// 使用信号量代替临界区
HANDLE hWrite = ::CreateSemaphore( NULL, 1, 1, NULL ) // 写开始信号
HANDLE hRead= ::CreateSemaphore( NULL, 1, 1, NULL ) // 读开始信号
// 计数器的互斥保汪凯护
HANDLE hRCMutex = ::CreateMutex( NULL, FALSE, NULL )
HANDLE hWCMutex = ::CreateMutex( NULL, FALSE, NULL )
// 在写优先中读信号
HANDLE hReadMutex = ::CreateMutex( NULL, FALSE, NULL )
// 从测试数据文件中获取的线程信息
struct ThreadInfo
{
ThreadInfo()
{
nSerialNo = 0
cType = '^'
dDelayTime = 0.0
dOpeTime= 0.0
}
int nSerialNo// 线程序号
charcType// 线程类别(判断是读者还是写者线程)
double dDelayTime // 线程延迟时间
double dOpeTime // 线程读写 *** 作时间
}
///困大唤//////////////////////////仿配//////////////////////////////////////////////
// 读者优先---读者线程
// P:读者线程信息
void RP_ReaderThread(void *p)
{
// 线程序号
int nSerialNo = ((ThreadInfo*)(p))->nSerialNo
DWORD dwReadTime = (DWORD)(((ThreadInfo*)(p))->dOpeTime * INTE_PER_SEC )
DWORD dwDelay = (DWORD)(((ThreadInfo*)(p))->dDelayTime * INTE_PER_SEC )
Sleep( dwDelay )
printf("Reader thread %d sents the reading require.\n",nSerialNo)
// 读者数目增加
WaitForSingleObject( hRCMutex, INFINITE )
nReaderCnt++
if( nReaderCnt == 1 )
{
// 第一个读者, 写保护信号,实现读写互斥
WaitForSingleObject( hWrite, INFINITE )
}
ReleaseMutex(hRCMutex)
// 读文件
printf( "Reader thread %d begins to read file.\n", nSerialNo )
Sleep( dwReadTime )
printf( "Reader thread %d finished reading file.\n", nSerialNo )
// 读者数目减少
WaitForSingleObject( hRCMutex, INFINITE )
nReaderCnt--
if( nReaderCnt == 0 )
{
// 如果所有的读者读完, 释放写保护信号
ReleaseSemaphore( hWrite, 1, NULL )
}
ReleaseMutex(hRCMutex)
}
//////////////////////////////////////////////////////////////
// 读者优先---写者线程
// P:写者线程信息
void RP_WriterThread(void *p)
{
// 从参数中获得信息
int nSerialNo = ((ThreadInfo*)(p))->nSerialNo
DWORD dwWriteTime = (DWORD)(((ThreadInfo*)(p))->dOpeTime * INTE_PER_SEC )
DWORD dwDelay = (DWORD)(((ThreadInfo*)(p))->dDelayTime * INTE_PER_SEC )
Sleep( dwDelay )
printf("Write thread %d sents the writing require.\n",nSerialNo)
// 写保护信号
WaitForSingleObject( hWrite, INFINITE )
//写文件
printf( "Writer thread %d begins to write to the file.\n", nSerialNo )
Sleep( dwWriteTime )
printf( "Write thread %d finished writing to the file.\n", nSerialNo )
ReleaseSemaphore( hWrite, 1, NULL )
}
//////////////////////////////////////////////////////////////
// 读者优先处理函数
// file:文件名
void ReaderPriority( char *file )
{
//线程数目
int nThreadCnt = 0
//线程ID
DWORD dwThreadID = 0
// 初始化读写者计数
nReaderCnt = 0
// 线程对象的数组
HANDLE hThreads[MAX_THREAD_NUM]
ThreadInfo oThreadInfo[MAX_THREAD_NUM]
ifstream inFile
inFile.open ( file )
printf( "Reader Priority:\n\n" )
while( inFile )
{
// 读入每一个读者,写者的信息
inFile>>oThreadInfo[nThreadCnt].nSerialNo
inFile>>oThreadInfo[nThreadCnt].cType
inFile>>oThreadInfo[nThreadCnt].dDelayTime
inFile>>oThreadInfo[nThreadCnt].dOpeTime
if ( '^' != oThreadInfo[nThreadCnt].cType )
{
nThreadCnt++
}
inFile.get()
}
// 创建线程
for( int i = 0i<nThreadCnti++ )
{
if(( oThreadInfo[i].cType==READER ) || ( oThreadInfo[i].cType == 'r' ))
{
// 创建读者进程
hThreads[i] = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)(RP_ReaderThread),
&oThreadInfo[i], CREATE_SUSPENDED, &dwThreadID )
}
else
{
// 创建写线程
hThreads[i] = CreateThread( NULL, 0,(LPTHREAD_START_ROUTINE)(RP_WriterThread),
&oThreadInfo[i], CREATE_SUSPENDED, &dwThreadID )
}
}
// 启动线程
for( i = 0i<nThreadCnti++ )
{
ResumeThread( hThreads[i] )
}
// 等待所有的线程结束
WaitForMultipleObjects( nThreadCnt, hThreads, TRUE, INFINITE )
printf( "All reader and writer have finished operating.\n" )
}
////////////////////////////////////////////////////////
// 写者优先---读者线程
// P:读者线程信息
void WP_ReaderThread( void *p )
{
// 从参数中得到信息
int nSerialNo = ((ThreadInfo*)(p))->nSerialNo
DWORD dwReadTime = (DWORD)(((ThreadInfo*)(p))->dOpeTime * INTE_PER_SEC )
DWORD dwDelay = (DWORD)(((ThreadInfo*)(p))->dDelayTime * INTE_PER_SEC )
Sleep( dwDelay )
printf("Reader thread %d sents the reading require.\n",nSerialNo)
// 读信号互斥保护
WaitForSingleObject( hReadMutex, INFINITE )
// 读信号
WaitForSingleObject( hRead, INFINITE )
// 增加读者计数
WaitForSingleObject( hRCMutex, INFINITE )
nReaderCnt++
if(nReaderCnt==1)
{
// 如果是第1个读者, 写信号,以实现读写互斥
WaitForSingleObject( hWrite, INFINITE )
}
ReleaseMutex( hRCMutex )
ReleaseSemaphore( hRead, 1, NULL )
ReleaseMutex( hReadMutex )
// 读文件
printf( "Reader thread %d begins to read file.\n", nSerialNo )
Sleep( dwReadTime )
printf( "Reader thread %d finished reading file.\n", nSerialNo )
// 减少读者计数
WaitForSingleObject( hRCMutex, INFINITE )
nReaderCnt--
if( nReaderCnt == 0 )
{
// 最后一个读者, 唤醒写者
ReleaseSemaphore( hWrite, 1, NULL )
}
ReleaseMutex( hRCMutex )
}
///////////////////////////////////////////
// 写者优先---写者线程
// P:写者线程信息
void WP_WriterThread( void *p )
{
//从参数中获得信息
int nSerialNo = ((ThreadInfo*)(p))->nSerialNo
DWORD dwWriteTime = (DWORD)(((ThreadInfo*)(p))->dOpeTime * INTE_PER_SEC )
DWORD dwDelay = (DWORD)(((ThreadInfo*)(p))->dDelayTime * INTE_PER_SEC )
Sleep( dwDelay )
printf("Writer thread %d sents the writing require.\n",nSerialNo)
// 增加写者计数
WaitForSingleObject( hWCMutex, INFINITE )
nWriterCnt++
if( nWriterCnt == 1 )
{
// 为实现写者优先,获取读信号,从而阻塞读线程
WaitForSingleObject( hRead, INFINITE )
}
ReleaseMutex(hWCMutex)
// 写信号
WaitForSingleObject( hWrite, INFINITE )
printf( "Writer thread %d begins to write to the file.\n", nSerialNo )
Sleep( dwWriteTime )
printf( "Writer thread %d finished writing to the file.\n", nSerialNo )
ReleaseSemaphore( hWrite, 1, NULL )
// 减少写者计数
WaitForSingleObject( hWCMutex, INFINITE )
nWriterCnt--
if( nWriterCnt == 0 )
{
ReleaseSemaphore( hRead, 1, NULL )
}
ReleaseMutex(hWCMutex)
}
/////////////////////////////////////////////
// 写者优先处理函数
// file:文件名
void WriterPriority( char * file )
{
int nThreadCnt = 0
DWORD dwThreadID
HANDLE hThreads[MAX_THREAD_NUM]
ThreadInfo oThreadInfo[MAX_THREAD_NUM]
nReaderCnt=0
nWriterCnt=0
ifstream inFile
inFile.open (file)
printf("Writer priority:\n\n")
while(inFile)
{
inFile>>oThreadInfo[nThreadCnt].nSerialNo
inFile>>oThreadInfo[nThreadCnt].cType
inFile>>oThreadInfo[nThreadCnt].dDelayTime
inFile>>oThreadInfo[nThreadCnt].dOpeTime
if ( '^' != oThreadInfo[nThreadCnt].cType )
{
nThreadCnt++
}
inFile.get()
}
// 创建线程
for( int i = 0 i <nThreadCnti++ )
{
if(( oThreadInfo[i].cType == READER ) || ( oThreadInfo[i].cType == 'r' ))
{
//创建读者进程
hThreads[i] = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)(WP_ReaderThread),
&oThreadInfo[i], CREATE_SUSPENDED, &dwThreadID )
}
else
{
//创建写线程
hThreads[i] = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)(WP_WriterThread),
&oThreadInfo[i],CREATE_SUSPENDED,&dwThreadID)
}
}
// 启动线程
for( i = 0i<nThreadCnti++ )
{
ResumeThread( hThreads[i] )
}
// 等待所有的线程结束
WaitForMultipleObjects( nThreadCnt, hThreads, TRUE, INFINITE )
printf("All reader and writer have finished operating.\n")
}
/////////////////////////////////////////////////////
//主函数
int main(int argc,char *argv[])
{
char ch
while(true)
{
printf("*************************************\n")
printf(" 1.Reader Priority\n")
printf(" 2.Writer Priority\n")
printf(" 3.Exit to Windows\n")
printf("*************************************\n")
printf("Enter your choice(1,2,3): ")
do{
ch=(char)_getch()
}while(ch!='1'&&ch!='2'&&ch!='3')
system("cls")
if(ch=='3')
return 0
else if(ch=='1')
ReaderPriority("thread.dat")
else
WriterPriority("thread.dat")
printf("\nPress Any Key to Coutinue:")
_getch()
system("cls")
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)