I am working on a number of productive and single consumer issues. Let me thread function so that different threads can be named based on these numbers.
But during the formation of the thread, the program is crashing after counting 7. I think the problem is due to the nThreadNo variable; If I limit the count to less than 7 then it works fine. But if I count more than that, then it crashes.
void CEvent1Dlg :: CreateProducerThreads () {try {nThreadNo = new int20]; Memset (nThreadNo, 0,20); If return (nThreadNo == NULL); } Hold (...) {message box (_T ("memory allocation failed"), _t ("thread"), 1); Return; } Int i = 0; For (i = 0; i & lt; 20; i ++) {// nThreadNo = i + 1; NThreadNo [i] = I + 1; HWndProducer [i] = CreationFread (Zero, 0, (Lpathred_ROTEEnI) ProducerFIFFank, (Zero *) (NTTHREDN + I), 0, and DWProducerTrade [i]); If (hWndProducer [i] == faucet) {// error handler (text ("CreateThread")); ExitProcess (3); }} / WaitForMultipleObjects (20, hWndProducer, TRUE, INFINITE); } DWORD WINAPI ProducerThrdFunc (LPVOID n) {int * nThreadNo = (int *) n; Four chitrad nano [33]; Memset (chThreadNo, 0, 33); While (1) {Iowa (* nThreadNo, chThreadNo, 10); Char * pMsg1 = new charge [100]; Char * pMsg2 = New Charge [100]; Memset (pMsg1,0,100); Memset (pMsg2,0,100); Strapepy (PMS1, "Manufacturer"); Dome (pMsg1, "thread no:"); Strcat (pMsg1, chThreadNo); If (stThreadInfoProd.pEventQueue-> AddTail (pMsg1) == TRUE) {strcpy (psg2, "creator"); Dome (PMS2, "thread no:"); Strcat (pMsg2, chThreadNo); Dome (PMS2, "Added message"); } And {strcpy (psg2, "creator"); Dome (PMS2, "thread no:"); Strcat (pMsg2, chThreadNo); Strcat (pMsg2, "Failed to add message"); } Post Message (Stuttread Infrapod.Audunde Handle, UWMOnPDATPDriBrit, (WAPARAM) PMSS 2.0); Dome (pMsg1, "add message:"); //PostMessage(stThreadInfoProd.hWndHandle,UWM_ONUPDATEPRODUCERLIST ,(WPARAM)pMsg2,0); Sleep (3000); } Return 0; }
- You are zeroing the first 20 bytes of
nThreadNo , before 20 * sizeof (int) bytes you should not be. - There are other arrays that are listed in this code:
hWndProducer , dwProducerThreadID . Do they have enough elements?
Comments
Post a Comment