c++ - "printf" appears to be non-deterministic in Qt? -
i know "printf" standard-c , should deterministic. when run in qt see more non-deterministic response(clock cycles). due qt adding "pork" response?
i have multiple threads make call function uses mutex. when 1 thread enters set switch others can't until done. things appeared work ok acouple seconds , threads appeared killed off 10 1 thread. tried adding delay: (k=k+1: no help), (looping k=k+1: no help), (usleep works), , (printf) work @ creating random delay , allowing threads continue running.
void ccb::write(int ithread) { static bool buse = false; bool bdone = false; char cstr[20]; int poswrite;// = *m_poswrite; // issue of poswrite altered next extrance long k = 0; long m = 0; m_threadcount++; while(bdone == false){ if(buse == false){ buse = true; poswrite = *m_poswrite; memcpy(m_cmmessagecb + poswrite, &m_cmmessagewrite, sizeof(typecanmessage)); memset(cstr, '\0', 20); memcpy(cstr, (m_cmmessagecb + poswrite)->cmessage, 11); //fails: every 20 *m_poswrite = *m_poswrite + 1; if(*m_poswrite == m_inbufferlength) *m_poswrite = 0; bdone = true; buse = false; }else if(buse == true){ //why threads being killed ? // printf("t%d_%d ", ithread, m_threadcount);//non-deterministic value ? usleep(1);//non-deterministic value //k++;//delay of couple clock cycles not enough /* for(k = 0; k < ithread * 100; k++){//deterministic , fails resolve thread problem m++; } */ } } }
Comments
Post a Comment