实验:创建两条线程,线程的执行函数是取钱,(本实验有3个文件,其中account.c 和 account.h 文件是模拟银行取钱,存钱,查询余额的函数,test.c为主函数。由于账户里有10000元,两个人去取钱,结果同时取到了10000元
源码如下:
account.c
#include "account.h"
#include <assert.h>
#include <malloc.h>
#include <string.h>
Account *create_account(int code, double balance)
{
Account *r=(Account *)malloc(sizeof(Account));
assert(r!=NULL);
r->code=code;
r->balance=balance;
return r;
}
void destroy_account(Account *a)
{
assert(a!=NULL);
free(a);
}
do