|
Because pointers are evil. Check
this
FAQ for more on that topic. Also, i couldn't get it to work. Can't cast the iterator to a pointer. No idea how it can be done.
|
|
|
|
|
You should wrap your mutex calls in a class (open it in the constructor and release it in the destructor). This actually allows for the exception option (otherwise, throwing an exception would be bad since the code would not be exception safe).
Given what you are trying to do, I would probably pass in a reference to be returned to as an argument and return a bool or some other status indicator as a return value. It would make your code look something like this:
class MutexHolder
{
public:
MutexHolder(HANDLE mutex)
{
_Mutex = mutex;
WaitForSingleObject(_Mutex, INFINITE);
}
~MutexHolder()
{
ReleaseMutex(_Mutex);
}
private:
HANDLE _Mutex;
};
bool job_not_working(const your_deque_type& t)
{
if (t.m_JobState != JOB_WORKING)
{
return true;
}
}
bool CThreadPool::CJobQueue::getJob(CThreadPool::t_Job& job)
{
MutexHolder(m_JobListMutex);
deque<your_deque_type>::iterator it = find_if(m_JobList.begin(), m_JobList.end(), job_not_working);
if (it != m_JobList.end())
{
job = *it;
job.m_JobState = JOB_WORKING;
return true;
}
return false;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
The problem with that approach, is that you'd be copying the job object. That may not always be possible. If you're going to return a status value, I'd suggest the COM way of returning the job: pointer to pointer, or reference to pointer (if you're hell bent on using references)
--
From the Makers of Futurama
|
|
|
|
|
The object is stored in a deque, therefore it is already being copied. The only way to avoid that is to have the deque store pointers, in which case the approach still works, you just need to pass in a reference to a pointer instead.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I use boost::optional library for similar problems. But you return a reference and it introduces some limitations to what boost::optional library could do.
Good luck..
Orhun Birsoy
|
|
|
|
|
A bit off topic but you may want to consider using Window's built-in thread pool. Look up the QueueUserWorkItem API.
Steve
|
|
|
|
|
Befor you use SetDialogBkColor(RGB(0, 0, 0), RGB(0, 255, 0)); to set background color and textcolor on a dialog what must I use now?
|
|
|
|
|
MSDN says to handle the WM_CTLCOLOR message.
|
|
|
|
|
|
If you are using MFC add the message to your function map just as you would with any other window messages.
|
|
|
|
|
|
|
Does anybody know the order in which windows are painted? I have an owner drawn STATIC control which is the parent of an owner drawn BUTTON . The I handle all of the region clipping for child controls in my own code rather than using the WS_CLIPCHILDREN style. The trouble is the button does not recieve any WM_PAINT messages preventing it from being displayed. The parent is correctly clipped, though the region is filled with a NULL brush causing a hole in the window. The button recieves all other messages including mouse input and WM_WINDOWPOSCHANGED . With the latter, I call InvalidateRect() hoping to force a redraw, but the WM_PAINT is never recieved. The only way I have managed to paint the button is to send the WM_PAINT message myself, which I know is a bad thing to do.
|
|
|
|
|
I spent hours trying to fix this last night, get up this morning and the answer is staring me in the face. I was calling ValidateRect() from the static control which in turn would validate the chidren. Since WM_PAINT is only sent when there is an invalidated region it was failing. The solution was simply to validate the clipping region in the static control or to call BeginPaint() which does the same.
|
|
|
|
|
My application build using VS2005 now I want run it on the comp. which has only .net Framework 1.1 I put in app. directory
ATL80.dll
gdiplus.dll
mfc80.dll
mfc80ENU.dll
msvcirt.dll
msvcp80.dll
msvcr80.dll
msvcrt.dll
Am I missing somthing? May be I need more modules to avoid installation of .net Framework on that machine?
When I do regisration of my COM componetns I am getting error
somthing like "... Configuration error application could not be loaded reinstall could help to fix problem"
|
|
|
|
|
Do you use the .NET framework in your code? If so you'll need the .NET framework installed on
the machine. None of the dlls in your list have anything to do with .NET.
Mark
|
|
|
|
|
No I don't use .net Framework. I only use MFC80 and ATL30
|
|
|
|
|
Can you post the exact error instead of "somthing like"?
|
|
|
|
|
regsvr32 MyDll.dll
"Load library (MyDll.dll) failed. This application failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem."
|
|
|
|
|
|
Man thanks a lot it really helped. It was simple and so obvious.
I will build monument to you in Georgia Tbilisi at the city Victory park, with the short modest words on it. "Here is standing monument to the smart guy". And please don’t ask me where is Georgia Tbilisi I don’t know, I know it is real.
Just kidding
-- modified at 15:19 Friday 3rd November, 2006
|
|
|
|
|
Where is Georgia Tbilisi ?
|
|
|
|
|
By the way, what was the fix??
|
|
|
|
|
|
Cool thanks
|
|
|
|