Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows错误代码:298用于vc+中的有界缓冲区解决方案+; 为了解决这个问题,我在项目中遇到了有界缓冲区问题 这个,我使用2个信号灯满和空 写操作等待空信号量信号和满信号 完成写入后的信号量 读取操作等待满信号量信号和空信号 读取后的信号量 由于im使用读写阻塞调用,因此每个读写 写操作按顺序进行 我在windows中用VC++实现这个,但我面对的是windows 错误代码:298,同时发送空信号量,表示向信号量发送的帖子过多 错误的可能原因是什么 用信号灯做的 列表项_C++_Windows_Process_Operating System_Synchronization - Fatal编程技术网

Windows错误代码:298用于vc+中的有界缓冲区解决方案+; 为了解决这个问题,我在项目中遇到了有界缓冲区问题 这个,我使用2个信号灯满和空 写操作等待空信号量信号和满信号 完成写入后的信号量 读取操作等待满信号量信号和空信号 读取后的信号量 由于im使用读写阻塞调用,因此每个读写 写操作按顺序进行 我在windows中用VC++实现这个,但我面对的是windows 错误代码:298,同时发送空信号量,表示向信号量发送的帖子过多 错误的可能原因是什么 用信号灯做的 列表项

Windows错误代码:298用于vc+中的有界缓冲区解决方案+; 为了解决这个问题,我在项目中遇到了有界缓冲区问题 这个,我使用2个信号灯满和空 写操作等待空信号量信号和满信号 完成写入后的信号量 读取操作等待满信号量信号和空信号 读取后的信号量 由于im使用读写阻塞调用,因此每个读写 写操作按顺序进行 我在windows中用VC++实现这个,但我面对的是windows 错误代码:298,同时发送空信号量,表示向信号量发送的帖子过多 错误的可能原因是什么 用信号灯做的 列表项,c++,windows,process,operating-system,synchronization,C++,Windows,Process,Operating System,Synchronization,信号量创建: string semName = m_mqName; semName.append(SEMAPHORE_FULL_NAME_SUFFIX); cout<<"\n <MessageQueue<DType, size>::CreateMsgQSemaphores ()> Semaphore name = "<<semName<<endl; m_mqFullSemaphore = CreateSemaphore( N

信号量创建:

string semName = m_mqName;
semName.append(SEMAPHORE_FULL_NAME_SUFFIX); 
cout<<"\n <MessageQueue<DType, size>::CreateMsgQSemaphores ()> Semaphore name = "<<semName<<endl;
m_mqFullSemaphore = CreateSemaphore( 
    NULL,                       // default security attributes
    0,                          // initial count
    size,                       // maximum count
    semName.c_str());           //semaphore name
if (m_mqFullSemaphore == nullptr) 
{
    cout<<"ERROR::CreateSemaphore Failed, Name:"<<semName<<",error code:"<<GetLastError()<<endl;
    CloseHandle(m_mqMutex); // close the existing m_mqMutex
    createSemaphoresStatus = CreateMsgQSemaphoresFailedError;
}
else if (ERROR_ALREADY_EXISTS == GetLastError())
{
    cout<<"\n <MessageQueue<DType, size>::CreateMsgQSemaphores ()>::WARNING: 'full' Semaphore exist.. "<<semName<<endl; 
}
else
    //cout<<"***INFO:: semaphore created: m_mqFullSemaphore= "<<m_mqFullSemaphore<<endl;    

//------------------------------------------Empty semaphore creation--------------------------------------------//

semName = m_mqName;
semName.append(SEMAPHORE_EMPTY_NAME_SUFFIX);
//cout<<"\n <MessageQueue<DType, size>::CreateMsgQSemaphores ()> Semaphore name = "<<semName<<endl;
m_mqEmptySemaphore = CreateSemaphore( 
    NULL,                       // default security attributes
    size,                       // initial count
    size,                       // maximum count
    semName.c_str());           // semaphore Name
if(m_mqEmptySemaphore == nullptr)
{
    cout<<"\n <MessageQueue<DType, size>::CreateMsgQSemaphores ()>::ERROR: Create empty Semaphore failed.. "<<semName<<endl;
    CloseHandle(m_mqMutex); // close the existing m_mqMutex
    createSemaphoresStatus = CreateMsgQSemaphoresFailedError;
}
string semName=m_mqName;
semName.append(信号量\全名\后缀);

可能您的初始错误是超出了
STATUS\u SEMAPHORE\u LIMIT\u
-
试图释放信号量,使其超过最大计数。
信号量的
lInitialCount
lMaximumCount
是什么?如何创建它?m_mqFullSemaphore=CreateSemaphore(NULL,0,sizeofmgq,name)初始和最大计数的具体值是多少?更新code@RbMm即使im将信号量最大计数的值设置为5,第一次尝试释放信号量本身也会导致错误
DWORD dwFullSemaphoreWaitResult  = WaitForSingleObject(m_mqFullSemaphore, 
timeoutVal);//wair for full semaphore
if(dwFullSemaphoreWaitResult== WAIT_OBJECT_0) // got the full semaphore
{
    //proceed further

    DWORD dwMutexWaitResult = WaitForSingleObject( m_mqMutex, timeoutVal);  // no time-out interval
    //Queue_Mutex_Handler mutexHandler(m_mqMutex); 
    //RAII

    LOG_MSG("SUCCESS: to aquire m_mqFullSemaphore:"<<m_mqName);



    switch (dwMutexWaitResult) 
    {
        case WAIT_OBJECT_0: // got ownership of the mutex
        {
            LOG_MSG("SUCCESS: to aquire m_mqMutex:"<<m_mqName);
            size_t qSize = 0;

            if(! m_pMsgQueueImpl->Dequeue(destMsg,qSize))
            {
                LOG_MSG("SUCCESS: Reached here:"<<m_mqName);
                LOG_MSG("ERROR: Dequeue failed, MSG Queue is Empty:"<< m_mqName);
                //ReleaseMutex(m_mqMutex);
                execResult = MQState_Queue_Empty_Error;

                if(0 == ReleaseMutex(m_mqMutex))
                {
                    LOG_MSG("Release mutex error:"<<GetLastError());
                }
            }
            else
            {
                int semCount = 0;
                LOG_MSG("MQ POP successful:"<< m_mqName<<", qSize="<<qSize);
                //ReleaseMutex(m_mqMutex);

                if(0 == ReleaseMutex(m_mqMutex))
                {
                    LOG_MSG("Release mutex error:"<<GetLastError());
                }

                if ( 0 == ReleaseSemaphore( 
                                    m_mqEmptySemaphore,  // handle to semaphore
                                    1,                  // increase count by one
                                    NULL))          // not interested in previous count
                {
                    //LOG_MSG("semCount = "<<semCount);
                    LOG_MSG("Release Empty Semaphore error: "<<GetLastError());
                }
                else
                {
                    //LOG_MSG("semCount = "<<semCount);
                    LOG_MSG("empty Semaphore signalled successfully");
                }
                return (int)qSize;
            }
           break;
        }
        case WAIT_TIMEOUT:
        {
            LOG_MSG("ERROR: Failed to aquire Mutex:"<<m_mqName<<", due to Timeout:"<<timeoutVal);
            execResult = MQState_QOpTimeOut_Error;
            break;
        }               
        default:        // The thread got ownership of an abandoned mutex 
        {
            LOG_MSG("ERROR: Failed to aquire Mutex:"<<m_mqName<<", due to GetLastError:"<<GetLastError());
            execResult = MQState_Queue_Unhandled_Error; 
        }
    } // end of switch (dwMutexWaitResult)
}
else if(dwFullSemaphoreWaitResult == WAIT_TIMEOUT)
{
    LOG_MSG("ERROR: Failed to aquire m_mqFullSemaphore:"<<m_mqName<<", due to Timeout:"<<timeoutVal);
    execResult = MQState_QOpTimeOut_Error;
}               
else 
{
    LOG_MSG("ERROR: Failed to aquire m_mqFullSemaphore:"<<m_mqName<<", GetLastError:"<<GetLastError());
    execResult = MQState_Queue_Unhandled_Error; 
}

if(execResult != MQState_QOp_Success)
    return execResult;
//=================================================================================================

//LOG_FUNC_END;
return execResult;
MSG_QUEUE_STATUS execResult = MQState_QOp_Success; 

//Wait for empty semaphore
DWORD dwSemaphoreWaitResult = WaitForSingleObject( m_mqEmptySemaphore,    // handle to mutex
                                                    timeoutValInMs);      // time-out interval
LOG_MSG("m_mqEmptySemaphore: "<<m_mqEmptySemaphore);
LOG_MSG("Got the m_mqEmptySemaphore");
//Wait for mutex 

if(dwSemaphoreWaitResult == WAIT_OBJECT_0)
{

    DWORD dwMutexWaitResult = WaitForSingleObject( m_mqMutex,           // handle to mutex
                                                    timeoutValInMs);    // time-out interval
    //Queue_Mutex_Handler mutexHandler(m_mqMutex); 
    LOG_MSG("Got the m_mqMutex");
    switch(dwMutexWaitResult)
    {
        case WAIT_OBJECT_0:
            LOG_MSG("going to send Message");

            if(m_pMsgQueueImpl->Enqueue(srcMsg) )
            {
                LOG_MSG("Message Sent successfully");
                //int semCount;
                if(0 == ReleaseMutex(m_mqMutex))
                {
                    LOG_MSG("Release mutex error:"<<GetLastError());
                }
                if ( 0 == ReleaseSemaphore( 
                                    m_mqFullSemaphore,  // handle to semaphore
                                    1,                  // increase count by one
                                    NULL))              // not interested in previous count
                {
                    //LOG_MSG("semCount = "<<semCount);
                    LOG_MSG("Release full Semaphore error: "<<GetLastError());
                }
                else
                {
                    //LOG_MSG("semCount = "<<semCount);
                    LOG_MSG("full Semaphore signalled successfully");
                }
                ///++++++++++++++
            }
            else
            {
                LOG_MSG("ERROR: Enqueue failed, MSG Queue is Full, QName = "<< m_mqName);

                if(0 == ReleaseMutex(m_mqMutex))
                {
                    LOG_MSG("Release mutex error:"<<GetLastError());
                }
                execResult = MQState_Queue_Full_Error;
            }
        break;  
        case WAIT_TIMEOUT:
            LOG_MSG("ERROR: Failed to aquire MsgQueue Mutex:"<<m_mqName<<", due to Timeout:"<<timeoutValInMs);
            execResult = MQState_QOpTimeOut_Error;
        break;
        default:
            LOG_MSG("ERROR: Failed to aquire MsgQueue Mutex:"<<m_mqName);
            execResult = MQState_Queue_Unhandled_Error; 
    }//switch ends
}
else if(WAIT_TIMEOUT==dwSemaphoreWaitResult)
{
    LOG_MSG("ERROR: Failed to aquire MsgQueue semaphore:"<<m_mqName<<", due to Timeout:"<<timeoutValInMs);
    execResult = MQState_QOpTimeOut_Error;
}
else
{
    LOG_MSG("ERROR: Failed to aquire MsgQueue semaphore:"<<m_mqName);
    execResult = MQState_Queue_Unhandled_Error; 
}
//RAII

//LOG_FUNC_END;
return execResult;