請問為什么一運行下邊的程序就說什么內(nèi)存不能written,然后出錯
#include "stdafx.h"#include <conio.h>#include <stdlib.h>#include <fstream.h>#include <io.h>#include <string.h> #include <stdio.h>#include "windows.h"int customer[10];void bank1(int i){if(customer[i]=0){customer[i]=1;HANDLE mutex1;DWORD wait_mutex;mutex1=OpenMutex(MUTEX_ALL_ACCESS,FALSE,"mutex1");wait_mutex=WaitForSingleObject(mutex1,-1);cout<<"一號柜臺叫"<<i<<"號"<<endl;cout<<"一號柜臺服務中"<<endl;Sleep(1000);ReleaseMutex(mutex1);cout<<"一號柜臺服務完畢"<<endl;}}void bank2(int i){if(customer[i]=0){customer[i]=1;HANDLE mutex2;DWORD wait_mutex;mutex2=OpenMutex(MUTEX_ALL_ACCESS,FALSE,"mutex2");wait_mutex=WaitForSingleObject(mutex2,-1);cout<<"二號柜臺叫"<<i<<"號"<<endl;cout<<"二號柜臺服務中"<<endl;Sleep(800);ReleaseMutex(mutex2);cout<<"二號柜臺服務完畢"<<endl;}}void bank3(int i){if(customer[i]=0){customer[i]=1;HANDLE mutex3;DWORD wait_mutex;mutex3=OpenMutex(MUTEX_ALL_ACCESS,FALSE,"mutex3");wait_mutex=WaitForSingleObject(mutex3,-1);cout<<"三號柜臺叫"<<i<<"號"<<endl;cout<<"三號柜臺服務中"<<endl;Sleep(500);ReleaseMutex(mutex3);cout<<"三號柜臺服務完畢"<<endl;}}void main(){for (int i=0;i<10;i++){customer[i]=0;}HANDLE mutex1;HANDLE mutex2;HANDLE mutex3;mutex1=CreateMutex(NULL,FALSE,"mutex1");mutex2=CreateMutex(NULL,FALSE,"mutex2");mutex3=CreateMutex(NULL,FALSE,"mutex3");HANDLE h_Thread[10];DWORD a;for( i=0;i<10;i++){ h_Thread[i]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)bank1,&i,0,&a);h_Thread[i]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)bank2,&i,0,&a);h_Thread[i]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)bank3,&i,0,&a);WaitForSingleObject(h_Thread[i],5000);}}
查看完整描述