Click here to Skip to main content
15,913,910 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
CPallini12-May-07 1:08
mveCPallini12-May-07 1:08 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
Daniel Grunwald13-May-07 2:59
Daniel Grunwald13-May-07 2:59 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
CPallini13-May-07 10:38
mveCPallini13-May-07 10:38 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
Stephen Hewitt13-May-07 14:04
Stephen Hewitt13-May-07 14:04 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
CPallini13-May-07 21:15
mveCPallini13-May-07 21:15 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
Stephen Hewitt13-May-07 14:01
Stephen Hewitt13-May-07 14:01 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
CPallini13-May-07 21:05
mveCPallini13-May-07 21:05 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
Stephen Hewitt13-May-07 21:23
Stephen Hewitt13-May-07 21:23 
Then consider this:
==================
// Console.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <process.h>

using namespace std;

unsigned __stdcall ThreadFn(void *)
{
for (;;)
{
// Comment these two lines out and the program will not deadlock. With them it will!
int *pInt = new int;
delete pInt;
}

return 0;
}

int main(int arvc, char* argv[])
{
for (;;)
{
unsigned unused;
unsigned long res = _beginthreadex(
NULL, // void *security
0, // unsigned stack_size
&ThreadFn, // unsigned ( __stdcall *start_address )( void * )
NULL, // void *arglist
0, // unsigned initflag
&unused // unsigned *thrdaddr
);
if (res==0)
{
cerr << "Failed to create thread!" << endl;
return 1;
}

for (int i=1; i<=1000; ++i)
{
int *pInt = new int;
delete pInt;
cout << i << " ";
}

HANDLE hThread = reinterpret_cast<HANDLE>(res);

// Comment this line out and the program will not deadlock. With it it will!
TerminateThread(hThread, 0);

CloseHandle(hThread); // We don't need the HANDLE anymore so close it.
}

return 0;
}


Steve
GeneralRe: Breaking out of a blocking function...[Threads] Pin
CPallini13-May-07 21:35
mveCPallini13-May-07 21:35 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
Stephen Hewitt13-May-07 21:37
Stephen Hewitt13-May-07 21:37 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
CPallini13-May-07 21:55
mveCPallini13-May-07 21:55 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
Stephen Hewitt13-May-07 22:19
Stephen Hewitt13-May-07 22:19 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
CPallini13-May-07 22:24
mveCPallini13-May-07 22:24 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
Stephen Hewitt13-May-07 22:28
Stephen Hewitt13-May-07 22:28 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
CPallini13-May-07 22:37
mveCPallini13-May-07 22:37 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
Stephen Hewitt13-May-07 22:44
Stephen Hewitt13-May-07 22:44 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
CPallini14-May-07 9:13
mveCPallini14-May-07 9:13 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
Stephen Hewitt15-May-07 13:48
Stephen Hewitt15-May-07 13:48 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
CPallini15-May-07 20:23
mveCPallini15-May-07 20:23 
AnswerRe: Breaking out of a blocking function...[Threads] Pin
Stephen Hewitt11-May-07 21:31
Stephen Hewitt11-May-07 21:31 
GeneralRe: Breaking out of a blocking function...[Threads] Pin
Eytukan11-May-07 23:10
Eytukan11-May-07 23:10 
QuestionWebbrowser control screen shot - a Challenging task Pin
llp00na11-May-07 5:18
llp00na11-May-07 5:18 
AnswerRe: Webbrowser control screen shot - a Challenging task Pin
Teashirt211-May-07 5:26
Teashirt211-May-07 5:26 
GeneralRe: Webbrowser control screen shot - a Challenging task Pin
llp00na11-May-07 6:12
llp00na11-May-07 6:12 
Questionfopen, fwrite access problem Pin
AAKAra11-May-07 4:54
AAKAra11-May-07 4:54 

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.