Click here to Skip to main content
16,010,876 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralCListCtrl and selected rows in a dialog Pin
Peter Jones3-May-01 14:54
Peter Jones3-May-01 14:54 
GeneralRe: CListCtrl and selected rows in a dialog Pin
Nick Blumhardt3-May-01 16:53
Nick Blumhardt3-May-01 16:53 
GeneralRe: CListCtrl and selected rows in a dialog Pin
Peter Jones3-May-01 18:37
Peter Jones3-May-01 18:37 
GeneralRe: CListCtrl and selected rows in a dialog Pin
Tomasz Sowinski3-May-01 23:54
Tomasz Sowinski3-May-01 23:54 
GeneralRe: CListCtrl and selected rows in a dialog Pin
Peter Jones4-May-01 3:18
Peter Jones4-May-01 3:18 
GeneralDB_NUMERIC Pin
Nick Blumhardt3-May-01 14:19
Nick Blumhardt3-May-01 14:19 
GeneralRe: DB_NUMERIC Pin
Nick Blumhardt3-May-01 16:49
Nick Blumhardt3-May-01 16:49 
GeneralMulti-threaded exception Pin
3-May-01 13:16
suss3-May-01 13:16 
Okay, so I have this multi-threaded app. It shows a dialog with a 'Start' button on it. You click start, it starts a thread. That thread in turn starts a user specified number of other threads that do actual work and block when they finish( See CThread::WaitForEnd() ).

The problem is, if I specify a large number of threads, some of them never end. i.e. Start 100 threads, wait until they stop (WM_TIMER sets a mutex protected BOOL), the debug window shows 0xNNNN exited etc. but locks up before they all exit (i.e. 80 will but the last 20 won't). Task manager says there are still threads open ( 10, 20, 30 etc. ). What on earth would cause this behaviour??? Can anyone help?

NB: I got it to do an unhandled exception on a call to WaitForSingleObject() in CThread::WaitForEnd(). I can't reproduce it however so I don't know if it has anything to do with the problem...



UINT CDlgBlah::ThreadProc()
{
CThread* arrThreads = new CThread[ dwThreadCount ];

hMutex = CreateMutex( NULL, FALSE, NULL );

for( DWORD dw = 0; dw < dwThreadCount; dw ++ )
{
arrThreads[ dw ].m_rnd = rand() % RAND_MAX;
arrThreads[ dw ].Begin()
}

for( dw = 0; dw < dwThreadCount; dw ++ )
arrThreads[ dw ].WaitForEnd(); // ##### Stops here

// ##### Never gets here
AfxGetMainWnd()->SendMessage( UWM_SHOWRESULTS ); // Update display (safe?)

return 0;
}



class CThread : public CObject
{
public:
CThread();
virtual ~CThread();

BOOL Begin( void );
void WaitForEnd( void );
void DoWork( void );

static UINT ThreadProc(LPVOID pObj);

int m_rnd;

private:
CWinThread* m_pThread;
}

BOOL CThread::Begin()
{
m_pThread = AfxBeginThread( ThreadProc, this );

return m_pThread != NULL;
}

UINT CThread::ThreadProc( LPVOID pObj )
{
CThread* pThread = (CThread*)pObj;

pThread->DoWork(); // Do some work

return 0;
}

void CThread::WaitForEnd()
{
WaitForSingleObject( m_pThread->m_hThread, INFINITE );
}

void CThread::DoWork()
{
srand( rnd );

while( StillWorking() ) // WaitForSingleObject in here etc.
Sleep( rand() % 250 )
}
GeneralRe: Multi-threaded exception Pin
4-May-01 4:48
suss4-May-01 4:48 
QuestionMessages? Pin
XKent3-May-01 11:55
XKent3-May-01 11:55 
AnswerRe: Messages? Pin
3-May-01 17:47
suss3-May-01 17:47 
GeneralToolbar Button Invisible Pin
3-May-01 8:44
suss3-May-01 8:44 
GeneralSending windows messages for socket activity Pin
3-May-01 7:40
suss3-May-01 7:40 
GeneralRe: You need the good book about Socket Pin
Masaaki Onishi3-May-01 17:49
Masaaki Onishi3-May-01 17:49 
Generalbuttons have icon and caption (as "START") Pin
3-May-01 7:12
suss3-May-01 7:12 
GeneralRe: buttons have icon and caption (as Pin
Davide Calabro3-May-01 7:36
Davide Calabro3-May-01 7:36 
GeneralRe: buttons have icon and caption (as Pin
3-May-01 8:13
suss3-May-01 8:13 
GeneralRe: buttons have icon and caption (as Pin
Davide Calabro3-May-01 20:51
Davide Calabro3-May-01 20:51 
GeneralBitmap question Pin
3-May-01 6:52
suss3-May-01 6:52 
GeneralRe: Bitmap question Pin
Christian Graus3-May-01 13:20
protectorChristian Graus3-May-01 13:20 
GeneralRe: Bitmap question Pin
4-May-01 0:46
suss4-May-01 0:46 
GeneralHELP !!! comunication between dialogs! Pin
3-May-01 6:04
suss3-May-01 6:04 
GeneralRe: HELP !!! comunication between dialogs! Pin
Christian Graus3-May-01 13:24
protectorChristian Graus3-May-01 13:24 
GeneralRe: HELP !!! comunication between dialogs! Pin
Masaaki Onishi3-May-01 17:17
Masaaki Onishi3-May-01 17:17 
Generalsimple for statement can't work! Pin
hearties3-May-01 5:42
hearties3-May-01 5:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.