|
You haven't been reading your documentation!!!
Try this.
UINT __cdecl ExecuteThread( LPVOID pParam );
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
The reason I ended up trying void, along with any other things is that UNIT dosn't show up as a data type. Is there a header that needs to be included? Having trouble researching it because everything that comes back is about unit testing.
From one page it looked like UNIT meant use, int, long, or short, but tried and non of those worked. Tried with and without the __cdecl as well.
Never come across the UNIT before and wishing right now I never had. Code looks basically the same. Any ideas?
void CVisualEmulatorDlg::OnBnClickedRun()
{
HWND hWnd = GetSafeHwnd();
CWinThread *pThread = AfxBeginThread(ExecuteThread, hWnd, THREAD_PRIORITY_NORMAL);
}
UNIT __cdecl ExecuteThread(LPVOID lParam)
{
MessageBox( (HWND)lParam, (LPCWSTR)"Thread Start", (LPCWSTR)"Secondary Thread", MB_OK );
}
|
|
|
|
|
typo typo typo typo
Its UINT not UNIT.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Wow.. sorry guys. Pretty embarased right now...but that fixed it.
Thanks a lot.
|
|
|
|
|
Killiconn wrote:
void ExecuteThread(LPVOID lParam)
Are you missing the ';' behind the function declaration.
By the way what are the compilation errors that you get?
The possible solutions for C2665 are
* Supply a conversion operator.
* Use explicit conversion.
but can't really say if they help you in resolving your problem
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Your worker thread function definition is wrong, check out here[^]
The function should not return void, the function signature should be as follows:
UINT __cdecl MyControllingFunction( LPVOID pParam );
|
|
|
|
|
I am currently writing a multi-threaded application using C++ and MFC. I am trying to write some code to keep track of my memory allocations (new) and my memory frees (delete). I have written aclass called MemoryChecker that is suppose to do this. To store the list of pointers that are allocated,
I am using STL which is not thread safe. To make it thread safe, I put a call to WaitForSingleObject
around the body of the function. I would expect to make this thread safe. Inside the member function
deleteItem, there is a static variable. It is initialized to true but later set to false. Before it is set to false, there is an assert statement that checks that the value is still true. However,
that assert statement is failing (sometimes). Therefore, I am thinking my lock is not working properly.
<br />
void<br />
MemoryChecker::deleteItem( void *ptr )<br />
{<br />
if ( WaitForSingleObject(mutexDeleteHandle, INFINITE) == WAIT_OBJECT_0 ) {<br />
if ( ptr == 0 ) {<br />
ReleaseMutex(mutexDeleteHandle);<br />
returneturn;<br />
}<br />
static bool go = true;<br />
bool found = false;<br />
NewList::iterator it = newList.begin();<br />
while ( it != newList.end() ) {<br />
if ( it->ptrValue == ptr ) {<br />
found = true;<br />
break;<br />
}<br />
it ++;<br />
}<br />
if ( found == false )<br />
found = true;<br />
else {<br />
assert( found );<br />
newList.erase( it );<br />
}<br />
assert( go );<br />
go = false;<br />
ReleaseMutex(mutexDeleteHandle);<br />
}<br />
}
I should also tell you that I create the lock, in another thread, with the following call:
mutexDeleteHandle = CreateMutex( NULL, FALSE, NULL );
Please note that the second parameter in CreateMutex is to specify who owns the lock and the
lock may not be owned by the thread making the call to WaitForSingleObject.
I am hoping that somebody here can tell me what I am doing wrong.
Thanks
Bob
modified on Thursday, March 19, 2009 6:26 PM
|
|
|
|
|
Your 'go' variable is static, it will be set to true once, so after you do 'go = false' it will remain false in following calls too.
p.s: Please put all of your code between <pre> and </pre> tags to make it easier to read.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Thanks for the response. You are 100% right. I am not awake today. I need to reinitialize the go flag every time to make it a valid test.
Now for your second point. I put the code between <pre> and </pre> but it did not preserve the white spacing. I do not know why. Any ideas?
Bob
|
|
|
|
|
Sorry, I see one small <pre> tag, and a large, only-half-there <code> tag.
|
|
|
|
|
blug,
Thanks for the response. I am not sure. Before I include code, I click on the formatting option code block. That is the option just to the left of inline code and to the right of BIG. Maybe, I should click on inline code and paste my code in there. Not Sure.
Bob
|
|
|
|
|
I am currently developing a multi-threaded application using C++ and MFC. Each thread calls new and delete to allocate and free memory. I am wondering if this is ok. In particular, if I have a routine that does the following, is it thread safe?
<br />
void<br />
WorkerClass::genRandomNumbers( double *randomNumbers, int count )<br />
{ <br />
double *ranList = new double[6];<br />
<br />
<br />
delete []ranList;<br />
}<br />
I am thinking that if two different threads are executing this routine at the same time, one might be allocating memory and the other freeing memory. Is that ok? One possibility is that Microsoft has put locks in there code to make sure that new and delete are thread safe. I have been unable to find documentation saying that they have or have not done this. I am hoping somebody out there can enlighten me on this issue.
Thanks
Bob
|
|
|
|
|
BobInNJ wrote: I am thinking that
My advice is not to use your own thinking about how multi-threading works. I strongly urge you to find some material designed to explain or teach multi-threading concepts and study it.
If this is something you decide to do, I can tell you that back when was starting out with threading I found this book[^] (the chapters on threading) very helpful. It was the first edition and I can't verify for you that the new editions contain the same material.
|
|
|
|
|
Perfectly safe. Unless you allocate something static. like
void
WorkerClass::genRandomNumbers( double *randomNumbers, int count )
{
static int i =0;
i = blahaha
}
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
VuNic wrote: Perfectly safe
Really? Even though you have no idea what is happening in the "details not shown"?
|
|
|
|
|
Oops! that was not to negate your message up there.. as you see it's all posted at the same time. "Perfectly-Safe" is perfectly restricted to that block of code he posted. Certainly I wanted to add a note asking him to look at the JR book you hrefed. but felt quite lazy to edit the text again
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
Automatic variables (like ranlist ) are thread safe.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Everyone has there own definition of "mean", that seems far meaner than any of the offensive things I post to people!
|
|
|
|
|
new will call malloc, which (eventually) calls HeapAlloc on the module CRT heap.
If you look at the Heap* API function docs you will see that they are thread safe by default (though this feature can be disabled) ... actually, to be precise, malloc will use a CRT lock (critical section) to lock the heap, but the effect is the same.
So yes, new and delete are thread safe.
As to your example; as led mike pointed out, it depends on what you are doing in 'Do some work, details not shown'.
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
I have an edit control in a CFormview dialog.
The edit control is DDXed to a some special class which is giving hyperlink functionality.
The control is disappearing or its background becomes same as the dialog sometime and when mouse cursor goes on top of it, it appears from then.
It happens mostly when setting text on that control (by function call) and
the control's class calls "RedrawWindow()", "InvalidateRect" & "UpdateWindow()" for the parent dialog(CFormView) of control when setting text on it.
The problem is happening in Win XP system and not in Vista.
The Formview is using "CreateSolidBrush()" and "FillRect()" function inside OnPaint() to change its back color.
Any suggstion would be greatly appreciable..
--
"Programming is an art that fights back!"
modified on Thursday, March 19, 2009 1:14 PM
|
|
|
|
|
Could it be that your edit is overlapped by some other control like a static for example?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Running VS2008, writing an SDI in VC++. Here's the code in a nutshell:
float htmin;
CString value;
value=mslstr.Mid(parse_start, parse_stop-parse_start);
htmin=atof(value);
VS throws the C4244 warning at the htmin=atof(value); line.
Am I missing something stupid here?
|
|
|
|
|
Nothing. atof returns you a double, and you are assigning it to a float. Nothing serious.
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
Thx, stickler for no warnings. Is only remedy to initialize htmin as double?
|
|
|
|
|
penny black wrote: Is only remedy to initialize htmin as double?
An explicit cast will do the trick
htmin = static_cast<float>(atof(value));
BTW atof is just an axample of misnamed function.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Thursday, March 19, 2009 2:46 PM
|
|
|
|