Click here to Skip to main content
15,892,809 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: best font for hindi Pin
CPallini29-Apr-09 21:09
mveCPallini29-Apr-09 21:09 
GeneralRe: best font for hindi Pin
Purish Dwivedi29-Apr-09 22:00
Purish Dwivedi29-Apr-09 22:00 
AnswerRe: best font for hindi Pin
Michael Schubert29-Apr-09 22:05
Michael Schubert29-Apr-09 22:05 
AnswerRe: best font for hindi Pin
Rajesh R Subramanian29-Apr-09 22:15
professionalRajesh R Subramanian29-Apr-09 22:15 
QuestionVisualC++ LineTo() call causes high usage of resouce, causing more RAM usage - Memory Not Releasing Pin
adepumadhu129-Apr-09 20:15
adepumadhu129-Apr-09 20:15 
AnswerRe: VisualC++ LineTo() call causes high usage of resouce, causing more RAM usage - Memory Not Releasing Pin
Cedric Moonen29-Apr-09 20:26
Cedric Moonen29-Apr-09 20:26 
AnswerRe: VisualC++ LineTo() call causes high usage of resouce, causing more RAM usage - Memory Not Releasing Pin
Perry Holman29-Apr-09 22:12
Perry Holman29-Apr-09 22:12 
QuestionRe: VisualC++ LineTo() call causes high usage of resouce, causing more RAM usage - Memory Not Releasing Pin
David Crow30-Apr-09 4:12
David Crow30-Apr-09 4:12 
QuestionNeed help on finishing this basic C program [modified] Pin
biggiant2200029-Apr-09 19:35
biggiant2200029-Apr-09 19:35 
AnswerRe: Need help on finishing this basic C program Pin
_AnsHUMAN_ 29-Apr-09 19:57
_AnsHUMAN_ 29-Apr-09 19:57 
GeneralRe: Need help on finishing this basic C program Pin
biggiant220001-May-09 6:29
biggiant220001-May-09 6:29 
AnswerRe: Need help on finishing this basic C program Pin
Michael Schubert29-Apr-09 22:12
Michael Schubert29-Apr-09 22:12 
QuestionRe: Need help on finishing this basic C program Pin
David Crow30-Apr-09 4:26
David Crow30-Apr-09 4:26 
AnswerRe: Need help on finishing this basic C program Pin
biggiant220001-May-09 6:07
biggiant220001-May-09 6:07 
QuestionRe: Need help on finishing this basic C program Pin
David Crow1-May-09 6:10
David Crow1-May-09 6:10 
QuestionMultithreading help in C++ Pin
Kiran Satish29-Apr-09 16:59
Kiran Satish29-Apr-09 16:59 
Hi all,

I am having a c++ file which is used to create mexfunction DLL that can be used to call a function from Matlab through dll. This is used to compute some mathematical calculations on a big matirx and for this I do it in two parallel threads each doing half matrix. At the end I combine both to generate full resultant matrix. For this, I create two different threads as follows-
HANDLE thd_handle[2];
DWORD WINAPI GenerateThread0(LPVOID param);
DWORD WINAPI GenerateThread1(LPVOID param);
void CreateResult0();
void CreateResult1();

void mexFunction(...mex function params....)
{
// do necessary variable declarations
// create two threads
thd_handle[0] = CreateThread(NULL,GenerateThread0, NULL, 0, NULL);
thd_handle[1] = CreateThread(NULL,GenerateThread1, NULL, 0, NULL);
WaitForMultipleObjects(2,thd_handle,true,INFINITE);
// prepare result
// return result to matlab
}
DWORD WINAPI GenerateThread0(LPVOID param)
{
CreateResult0();
return 0;
}
DWORD WINAPI GenerateThread1(LPVOID param)
{
CreateResult1();
return 0;
}
void CreateResult0()
{
//do some computations
}
void CreateResult1()
{
//do some computations
}

Everything is fine and good while doing as above and I used this for a long time without any problems. Now I am planning to make this more efficient by making it multithreading adaptable to the processor on which it runs. I have couple of systems which are like 4core/8core and would like to create threads dynamically. I came up with the following idea and implemented it and guess what it gives fatal errors while running and I highly suspect the way I am creating multiple threads.
HANDLE *thd_handle;
DWORD WINAPI GenerateThread(LPVOID param);
void CreateResult(unsigned int idx);

void mexFunction(...mexfunctionparams...)
{
//read in input params
//find (#processors*#logicalprocs*#coresperproc)=m_nThreads;
thd_handle = new HANDLE[m_nThreads-1];
//CreateThreads
for (unsigned int i=0; i < m_nThreads-1; i++ )
thd_handle[i] = CreateThread(NULL, GenerateThread, &i, 0, NULL);
WaitForMultipleObjects(m_nThreads-1,thd_handle, true,infinite);
//prepare result
//return result to matlab
}
DWORD WINAPI GenerateThread(LPVOID param)
{
DWORD iter = *(DWORD*)param;
CreateResult(iter);
retrun 0;
}
void CreateResult(unsigned int idx)
{
//compute result for this matrix size depending on idx
}

if I use the dll generated from this code, the program crashes... am I doing something fundamentally wrong here?? is there any other better way to achieve this??

thanks for any help,

PKNT

AnswerRe: Multithreading help in C++ Pin
Stuart Dootson29-Apr-09 20:48
professionalStuart Dootson29-Apr-09 20:48 
GeneralRe: Multithreading help in C++ Pin
Kiran Satish30-Apr-09 5:15
Kiran Satish30-Apr-09 5:15 
GeneralRe: Multithreading help in C++ Pin
Stuart Dootson30-Apr-09 6:16
professionalStuart Dootson30-Apr-09 6:16 
GeneralRe: Multithreading help in C++ Pin
Kiran Satish30-Apr-09 6:50
Kiran Satish30-Apr-09 6:50 
GeneralRe: Multithreading help in C++ Pin
Stuart Dootson30-Apr-09 6:55
professionalStuart Dootson30-Apr-09 6:55 
AnswerRe: Multithreading help in C++ Pin
KarstenK29-Apr-09 21:17
mveKarstenK29-Apr-09 21:17 
GeneralRe: Multithreading help in C++ Pin
Kiran Satish30-Apr-09 3:27
Kiran Satish30-Apr-09 3:27 
GeneralRe: Multithreading help in C++ Pin
KarstenK30-Apr-09 3:43
mveKarstenK30-Apr-09 3:43 
GeneralRe: Multithreading help in C++ Pin
Kiran Satish30-Apr-09 5:03
Kiran Satish30-Apr-09 5:03 

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.