📄 oks3.c
字号:
#include <stdlib.h>
#include <stdio.h>
#include "string.h"
#include "hello.h"
#include "hellop.h"
void HelloProc(short i,unsigned char * pszString)
{
printf("%s\n", pszString);
strcpy(pszString,"hello,RPC_Client!");
}
DWORD WINAPI funA(LPVOID lp)
{
//*temp=0;
float *temp;
temp=(float *)lp;
*temp+=110;
return 0;
}
void add(float *amount)
{
HANDLE a;
DWORD dwT;
// *temp=0;
a=CreateThread(NULL,0,funA,amount,0,&dwT);
WaitForSingleObject(a,INFINITE);
CloseHandle(a);
return;
}
/*
void add(float *amount)
{
*amount+=100;
}*/
DWORD WINAPI funproc(LPVOID lp)
{
operation *u2;
int i=0;
u2=(operation *)lp;
while(strcmp(account[i].account_number,u2->account_number)!=0)
{
if(i<count) i++;
else
{
re=-1;
return -1;
}
}
// 进入临界区
EnterCriticalSection(&g_cs);
if(u2->account_type=='d')
{
// 进入临界区
// EnterCriticalSection(&g_cs);
Sleep(4000);
account[i].account_balance+=u2->amount;
re=account[i].account_balance;//余额回传
// LeaveCriticalSection(&g_cs);//释放对该临界区对象的所有权
}
else if(u2->account_type=='w')
{
if(account[i].account_balance>=u2->amount)
{
// EnterCriticalSection(&g_cs);
Sleep(1000);
account[i].account_balance-=u2->amount;
re=account[i].account_balance;//余额回传
// LeaveCriticalSection(&g_cs);//释放对该临界区对象的所有权
}
else
{
re=-2;
return -2;
}
}
LeaveCriticalSection(&g_cs);//释放对该临界区对象的所有权
return 0;
}
int transact(operation *u1,float *moneny)
{
HANDLE a;
DWORD dwT;
re=0;
// *temp=0;
a=CreateThread(NULL,0,funproc,u1,0,&dwT);
WaitForSingleObject(a,INFINITE);
*moneny=re;
CloseHandle(a);
return 0;
}
DWORD WINAPI funproc1(LPVOID lp)
{
operation *u2;
int i=0;
u2=(operation *)lp;
while(strcmp(account[i].account_number,u2->account_number)!=0)
{
if(i<count) i++;
else
{
re=-1;
return -1;
}
}
// 进入临界区
EnterCriticalSection(&g_cs);
Sleep(1000);
re=1;
LeaveCriticalSection(&g_cs);//释放对该临界区对象的所有权
return 0;
}
int query(operation *u1,float *moneny)
{
HANDLE a;
DWORD dwT;
re=0;
// *temp=0;
a=CreateThread(NULL,0,funproc1,u1,0,&dwT);
WaitForSingleObject(a,INFINITE);
*moneny=re;
CloseHandle(a);
return 0;
}
//Sleep(4000);
// DeleteCriticalSection(&g_cs);//释放该临界区对象的资源
void Shutdown(void)
{
RPC_STATUS status;
int j;
freopen("moneydata.in","w",stdout);
for(j=0;j<count;j++)
printf("%s %s %f\n",account[j].account_number,account[j].account_name,account[j].account_balance);
freopen("moneydata1.in","w",stdout);
for(j=0;j<count;j++)
printf("%s %s %f\n",account[j].account_number,account[j].account_name,account[j].account_balance);
freopen("moneydata2.in","w",stdout);
for(j=0;j<count;j++)
printf("%s %s %f\n",account[j].account_number,account[j].account_name,account[j].account_balance);
/*
//printf("Calling RpcMgmtStopServerListening\n");
status = RpcMgmtStopServerListening(NULL);
//printf("RpcMgmtStopServerListening returned: 0x%x\n", status);
if (status) {
exit(status);
}
//printf("Calling RpcServerUnregisterIf\n");
status = RpcServerUnregisterIf(NULL, NULL, FALSE);
//printf("RpcServerUnregisterIf returned 0x%x\n", status);
if (status) {
exit(status);
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -