|
Im still not understand im getting 42 errors
|
|
|
|
|
biggiant22000 wrote: Im still not understand
Which part?
biggiant22000 wrote: im getting 42 errors
Start with the first one.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
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....)
{
thd_handle[0] = CreateThread(NULL,GenerateThread0, NULL, 0, NULL);
thd_handle[1] = CreateThread(NULL,GenerateThread1, NULL, 0, NULL);
WaitForMultipleObjects(2,thd_handle,true,INFINITE);
}
DWORD WINAPI GenerateThread0(LPVOID param)
{
CreateResult0();
return 0;
}
DWORD WINAPI GenerateThread1(LPVOID param)
{
CreateResult1();
return 0;
}
void CreateResult0()
{
}
void CreateResult1()
{
}
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...)
{
thd_handle = new HANDLE[m_nThreads-1];
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);
}
DWORD WINAPI GenerateThread(LPVOID param)
{
DWORD iter = *(DWORD*)param;
CreateResult(iter);
retrun 0;
}
void CreateResult(unsigned int 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
|
|
|
|
|
Have you run it in a debugger (that's easy enough to do - just specify Matlab as the target executable) so you can see where the exception occurs?
Some things that do jump out at me:
- As it says in the CreateThread[^] documentation,
A thread in an executable that calls the C run-time library (CRT) should use the _beginthreadex and _endthreadex functions for thread management rather than CreateThread and ExitThread; this requires the use of the multi-threaded version of the CRT. If a thread created using CreateThread calls the CRT, the CRT may terminate the process in low-memory conditions. - You pass a pointer to a stack variable in the CreateThread call. That's not a great idea - you can't guarantee that the newly created thread will assign to iter before i changes. Why not just pass the value of i rather than the address. Even though the param is an LPVOID, integer is convertible to LPVOID and vice versa.
One other thing - why use m_nThreads-1 all over the place - once your main thread enters WaitForMultipleObjects, there will be m_nThreads cores available for processing, as the WaitForMultipleObjects call will yield the core it's on.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for the reply... will try VC++ specific thread functions and see how it does and also the parameters thing.
Stuart Dootson wrote: One other thing - why use m_nThreads-1 all over the place - once your main thread enters WaitForMultipleObjects, there will be m_nThreads cores available for processing, as the WaitForMultipleObjects call will yield the core it's on.
this is for the system to be responsive for other applications/tasks that are running at the same time. I am leaving a core for this purpose.
thanks
PKNT
|
|
|
|
|
Kiran Satish wrote: this is for the system to be responsive for other applications/tasks that are running at the same time. I am leaving a core for this purpose.
That shows remarkable restraint
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I figured out the problem... nothing from the way I am assigning threads (but now I am using _beginthread/_endthread functions though), but an overseen logic mistake and improper reading of 2D matrices from a 3D matrix generated using OptiVec library. Now everything works fine. Thanks for your time.
PKNT
|
|
|
|
|
Kiran Satish wrote: nothing from the way I am assigning threads (but now I am using _beginthread/_endthread functions though), but an overseen logic mistake and improper reading of 2D matrices from a 3D matrix generated using OptiVec library
Doh!
Kiran Satish wrote: Now everything works fine
Good
Kiran Satish wrote: Thanks for your time
My pleasure
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I was looking for a "i++" somewhere
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Sorry, I do have i++ in there...
PKNT
|
|
|
|
|
i didnt see it here: for (unsigned int i=0; i < m_nThreads-1; )
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Well in the original program I have it, its a typo in y post and didn't had time to correct it in the morning when I replied to your reply.
PKNT
|
|
|
|
|
for (unsigned int i=0; i < m_nThreads-1; i++ )
thd_handle[i] = CreateThread(NULL, GenerateThread, &i, 0, NULL);
The problem is that you are taking the address of i and passing it to the thread function. However, by the time the thread function is able to start, i has likely changed and is probably invalid.
Since all you need is the actual value, just pass i (by casting it to LPVOID), and then in the thread function just pass param to CreateResult by casting it to a DWORD.
(I also don't understand why you keep subtracting one from your thread count. Why not just use the correct number to begin with?)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi All,
I wonder how can I make a combobox without using MFC. Can someone give me a clue about that.
Thanks a lot
|
|
|
|
|
HWND hCombo = ::CreateWindow( _T("ComboBox"), _T("Some Name") , WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST, 0,0, 300, 300, hParent, 0, hInstance,0 );
Where hParent is the parent window handle and hInstance is the instance handle of the application/module.
|
|
|
|
|
Hi,
I have a CTreeCtrl in an application. When I click on an item, I want to do a particuliar action. To do that, I have to know the number of the item in the tree: first, second, third an so on.
How can I retreive that information ?
Thanks,
Claude
|
|
|
|
|
Are tree controls supposed to be viewed that way. What happens to items 2..N when item 1 is expanded? Does item 2 become item 3, etc?
I would opt for using SetItemData() for each item/node in the tree.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Gagnon Claude wrote: To do that, I have to know the number of the item in the tree: first, second, third an so on
Number in the tree....how are you counting? Breadth first? Depth first?
And why do you need that - are you sure there's no other way of achieveing your objective?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: how are you counting?
See there's this roulette wheel and
|
|
|
|
|
|
Can I format the text to be displayed in a Rich Edit via Setsel ReplaceSel
in Editstream Call Back function before I copy it to the output buffer
thankx
|
|
|
|
|
ForNow wrote: Can I format the text to be displayed in a Rich Edit...before I copy it to the output buffer
Yes, maybe not with those exact methods, but you can edit/format it.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
[assumptions]You're using EM_STREAMIN to get text into a rich-edit control[/assumptions]
I don't see how that's going to work - the text isn't in the rich-edit control yet, so won't be accessible through the control.
I suspect the only way to do it is to tell the control that you're giving it RTF and annotate the text with RTF markup - here's the RTF spec[^]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Exactly what I was thinking
I am trying to display a Storage Dump From the Rich Edit
So...... On the left hand side I would have 0000010 the 16 bytes newline
000020
I would like to high light the storage location So...
In the call back function I would probably mark it up with XXXXXX
Once the text is in the Rich Edit Object. I would do A FindText to give me the index of
the current XXXXXX Setsel give it the attributes I want
Then ReplaceSel with the right Storage location number
thankx
Again
thnakx
|
|
|
|
|
hi,
i am creating some CStatic based controls on a dialog with a regular MFC DLL. (MFC statically linked)
so ,main application calls some functitons in DLL, Like: Create ,Resize ,Move
and DLL creates control on main app's dialog and manages control as main app needs
my problem is:
with this method , tooltips , TAB , CTRL + combinations do not work
could you help me to solve this problem, Please
thanks in anvance
|
|
|
|