C++ C++;调试断言失败,使用Windows.h互斥体
我有一个由此代码引起的问题:C++ C++;调试断言失败,使用Windows.h互斥体,c++,multithreading,concurrency,assertion,C++,Multithreading,Concurrency,Assertion,我有一个由此代码引起的问题: char KernelFS::mount(Partition* part) { WaitForSingleObject(mutexFS,INFINITE); int pos; for(pos=0; pos<26; pos++) if(mountedPartitions[pos] == 0) break; if(pos < 26) { mountedPartitions[pos] = part; bitVecto
char KernelFS::mount(Partition* part) {
WaitForSingleObject(mutexFS,INFINITE);
int pos;
for(pos=0; pos<26; pos++)
if(mountedPartitions[pos] == 0)
break;
if(pos < 26) {
mountedPartitions[pos] = part;
bitVectors[pos] = new BitVector(part);
fileEvidention[pos] = new ListHandler();
openedFiles[pos] = 0;
forbidOpening[pos] = false;
ReleaseMutex(mutexFS);
return intToChar(pos);
}
else {
ReleaseMutex(mutexFS);
return '0';
}
}
有3个线程正在执行,1个被阻塞,2个正在运行此代码;
它们首先调用mount,然后调用format(每个都有自己的参数分区对象p1和p2)。
第一次调用mount时,它总是会执行—然后在两个运行线程中的任意一个调用mount/format的下一次调用期间,会随机出现断言失败
通常,它在线程1期间失败-它调用mount(…)完成它,然后调用format(…)并在以下情况下失败:
删除文件证明[ChartPoint(pos)];
(在调试模式下,当我到达此指令时,即使我尝试进入F11,也会出现断言失败)
如果有关系的话。。。这是初始化:
char KernelFS::firstLetter = 'A'; // 'A' = 65
Partition* KernelFS::mountedPartitions[26] = {0}; // init. no partitions are mounted
BitVector* KernelFS::bitVectors[26] = {0}; // init. no partitions are mounted
bool KernelFS::forbidOpening[26] = {false};
long KernelFS::openedFiles[26] = {0};
ListHandler* KernelFS::fileEvidention[26] = {0};
HANDLE KernelFS::mutexFS = CreateMutex(0,0,0);
HANDLE KernelFS::unmountSem = CreateSemaphore(0,0,INFINITE,0);
我以前从未遇到过这个错误,我不知道如何调试它,也不知道是什么原因导致它。
提前谢谢你的帮助
编辑:
当我删除标记的代码行(并忽略内存泄漏)时,没有断言失败。这是什么巫术
!:) 已解决。应该是
删除文件证明[图表点(部分)];
……哪个行导致断言?断言的消息是什么?断言是在删除文件证据[…]后有注释的行上产生的;在(…)格式中,断言消息为:调试断言失败!路径第52行。。表达式:\块\类型\有效(pHead->nBlockUse)
char KernelFS::firstLetter = 'A'; // 'A' = 65
Partition* KernelFS::mountedPartitions[26] = {0}; // init. no partitions are mounted
BitVector* KernelFS::bitVectors[26] = {0}; // init. no partitions are mounted
bool KernelFS::forbidOpening[26] = {false};
long KernelFS::openedFiles[26] = {0};
ListHandler* KernelFS::fileEvidention[26] = {0};
HANDLE KernelFS::mutexFS = CreateMutex(0,0,0);
HANDLE KernelFS::unmountSem = CreateSemaphore(0,0,INFINITE,0);