Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing integer array in thread function
    text
    copied!<p>I am working on multiple producer and Single consumer problem.I wanted to pass Thread like 1,2,3 in the thread function so that individual thread can be named based on these number.</p> <p>But the program is crashing after count 7 while creating thread.I think problem is due to variable nThreadNo; if i limit the count less than 7 it works fine.but if i make count more than this it crashes.</p> <pre><code>void CEvent1Dlg::CreateProducerThreads() { try { nThreadNo = new int20]; memset(nThreadNo,0,20); if (nThreadNo ==NULL) return; }catch(...) { MessageBox(_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] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ProducerThrdFunc,(void*)(nThreadNo+i),0,&amp;dwProducerThreadID[i]); if (hWndProducer[i] == NULL) { //ErrorHandler(TEXT("CreateThread")); ExitProcess(3); } } //WaitForMultipleObjects(20,hWndProducer,TRUE,INFINITE); } DWORD WINAPI ProducerThrdFunc ( LPVOID n ) { int *nThreadNo = (int*)n; char chThreadNo[33]; memset(chThreadNo,0,33); while(1) { itoa(*nThreadNo,chThreadNo,10); char* pMsg1 = new char[100]; char* pMsg2 = new char[100]; memset(pMsg1,0,100); memset(pMsg2,0,100); strcpy(pMsg1,"Producer "); strcat(pMsg1," Thread No:"); strcat(pMsg1,chThreadNo); if (stThreadInfoProd.pEventQueue-&gt;AddTail(pMsg1)==TRUE) { strcpy(pMsg2,"Producer "); strcat(pMsg2," Thread No:"); strcat(pMsg2,chThreadNo); strcat(pMsg2," Added the Msg"); } else { strcpy(pMsg2,"Producer "); strcat(pMsg2," Thread No:"); strcat(pMsg2,chThreadNo); strcat(pMsg2,"failed to Add the Msg"); } PostMessage(stThreadInfoProd.hWndHandle,UWM_ONUPDATEPRODUCERLIST,(WPARAM)pMsg2,0); strcat(pMsg1," Adding Msg:"); //PostMessage(stThreadInfoProd.hWndHandle,UWM_ONUPDATEPRODUCERLIST,(WPARAM)pMsg2,0); Sleep(3000); } return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload