Guest DonDilworth Posted October 21, 2021 Posted October 21, 2021 My program uses CreateFileMapping so multiple processes can access a common data base. The program runs fine and produces the correct answers. But when all is finished, sometimes the Windows OS has crashed. Other programs won't load, and the Power | Restart button doesn't work. I have to run shutdown.exe and then cold start the PC. I UnmapViewOffile for each mapping I create, and then close the handle. Here is the code. Did I leave out anything? #pragma optimize("g", off ) // core 0 comes here to get addresses of arrays for other cores void preparederivmap( int &npas ) // create mapping of data for other cores { int size = 15001*412 + 128; TCHAR derivfilename[]= TEXT("SYNOPSYS_DERIV_DATA"); hMapping = CreateFileMapping( NULL ,nullptr, PAGE_READWRITE, 0, (size*sizeof(double)), derivfilename ); if (hMapping == NULL ) { panic( "Cannot open mapping file" ); } double *deriv = static_cast<double*> (MapViewOfFile(hMapping, FILE_MAP_ALL_ACCESS, 0, 0, 0 )); if ( !deriv ) { panic( "Cannot do MapView" ); } pderiv = deriv; size = 401; TCHAR delqfilename[]= TEXT("SYNOPSYS_DELQ_DATA"); hMapping2 = CreateFileMapping( NULL ,nullptr, PAGE_READWRITE, 0, (size*sizeof(double)), delqfilename ); if (hMapping2 == NULL ) { panic( "Cannot open mapping file" ); } double *delq = static_cast<double*> (MapViewOfFile(hMapping2, FILE_MAP_ALL_ACCESS, 0, 0, 0 )); if ( !delq ) { panic( "Cannot do MapView" ); } pdelq = delq; TCHAR scdrfilename[]= TEXT("SYNOPSYS_SCDR_DATA"); hMapping3 = CreateFileMapping( NULL ,nullptr, PAGE_READWRITE, 0, (size*sizeof(double)), scdrfilename ); if (hMapping3 == NULL ) { panic( "Cannot open mapping file" ); } double *scdr = static_cast<double*> (MapViewOfFile(hMapping3, FILE_MAP_ALL_ACCESS, 0, 0, 0 )); if ( !scdr ) { panic( "Cannot do MapView" ); } pscdr = scdr; SYNORUN( deriv, delq, scdr, &npas ); // returns only when all passes are done return; } void killderivmap( ) // delete mapping of data for other cores { UnmapViewOfFile( pderiv ); UnmapViewOfFile( pdelq ); UnmapViewOfFile( pscdr ); CloseHandle( hMapping ); CloseHandle( hMapping2 ); CloseHandle( hMapping3 ); } Continue reading... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.