Click here to Skip to main content
16,004,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Return value or Exception or something else ? Pin
Mr.Brainley3-Nov-06 6:29
Mr.Brainley3-Nov-06 6:29 
GeneralRe: Return value or Exception or something else ? Pin
Jörgen Sigvardsson3-Nov-06 6:37
Jörgen Sigvardsson3-Nov-06 6:37 
GeneralRe: Return value or Exception or something else ? Pin
Mr.Brainley3-Nov-06 6:41
Mr.Brainley3-Nov-06 6:41 
GeneralRe: Return value or Exception or something else ? Pin
Zac Howland3-Nov-06 10:52
Zac Howland3-Nov-06 10:52 
GeneralRe: Return value or Exception or something else ? Pin
Jörgen Sigvardsson3-Nov-06 11:39
Jörgen Sigvardsson3-Nov-06 11:39 
GeneralRe: Return value or Exception or something else ? Pin
Zac Howland3-Nov-06 17:11
Zac Howland3-Nov-06 17:11 
AnswerWhy not use a pointer ? Pin
Mr.Brainley3-Nov-06 6:23
Mr.Brainley3-Nov-06 6:23 
AnswerRe: Return value or Exception or something else ? Pin
Zac Howland3-Nov-06 8:53
Zac Howland3-Nov-06 8:53 
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);
		// I believe this should actually be OpenMutex
		// In which case, you would change the constructor arguement to a string
	}

	~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

GeneralRe: Return value or Exception or something else ? Pin
Jörgen Sigvardsson3-Nov-06 9:15
Jörgen Sigvardsson3-Nov-06 9:15 
GeneralRe: Return value or Exception or something else ? Pin
Zac Howland3-Nov-06 9:43
Zac Howland3-Nov-06 9:43 
AnswerRe: Return value or Exception or something else ? Pin
Orhun Birsoy3-Nov-06 11:53
Orhun Birsoy3-Nov-06 11:53 
AnswerRe: Return value or Exception or something else ? Pin
Stephen Hewitt5-Nov-06 11:56
Stephen Hewitt5-Nov-06 11:56 
QuestionColor?? Pin
Larsson3-Nov-06 5:17
Larsson3-Nov-06 5:17 
AnswerRe: Color?? Pin
Waldermort3-Nov-06 5:25
Waldermort3-Nov-06 5:25 
GeneralRe: Color?? Pin
Larsson3-Nov-06 5:43
Larsson3-Nov-06 5:43 
GeneralRe: Color?? Pin
Waldermort3-Nov-06 5:49
Waldermort3-Nov-06 5:49 
GeneralRe: Color?? Pin
Larsson3-Nov-06 5:52
Larsson3-Nov-06 5:52 
GeneralRe: Color?? Pin
Hamid_RT3-Nov-06 6:23
Hamid_RT3-Nov-06 6:23 
QuestionPainting in windows Pin
Waldermort3-Nov-06 5:00
Waldermort3-Nov-06 5:00 
AnswerRe: Painting in windows Pin
Waldermort3-Nov-06 16:57
Waldermort3-Nov-06 16:57 
QuestionVS2005 app distribution Pin
Alex_Y3-Nov-06 4:13
Alex_Y3-Nov-06 4:13 
AnswerRe: VS2005 app distribution Pin
Mark Salsbery3-Nov-06 5:17
Mark Salsbery3-Nov-06 5:17 
GeneralRe: VS2005 app distribution Pin
Alex_Y3-Nov-06 5:31
Alex_Y3-Nov-06 5:31 
GeneralRe: VS2005 app distribution Pin
Mark Salsbery3-Nov-06 5:34
Mark Salsbery3-Nov-06 5:34 
GeneralRe: VS2005 app distribution Pin
Alex_Y3-Nov-06 5:45
Alex_Y3-Nov-06 5:45 

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.