Click here to Skip to main content
15,900,664 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to prevent CMainFrame from restores???? Pin
MANISH RASTOGI3-Jul-07 18:46
MANISH RASTOGI3-Jul-07 18:46 
Questionruntime type casting Pin
wallbrick3-Jul-07 6:00
wallbrick3-Jul-07 6:00 
AnswerRe: runtime type casting Pin
Matthew Faithfull3-Jul-07 6:18
Matthew Faithfull3-Jul-07 6:18 
AnswerRe: runtime type casting Pin
led mike3-Jul-07 6:22
led mike3-Jul-07 6:22 
AnswerRe: runtime type casting Pin
Nuxser3-Jul-07 15:59
Nuxser3-Jul-07 15:59 
AnswerRe: runtime type casting Pin
Nuxser3-Jul-07 16:17
Nuxser3-Jul-07 16:17 
Questionget Distinguished Email id from GAL Pin
Ganesh_T3-Jul-07 5:47
Ganesh_T3-Jul-07 5:47 
QuestionThread syncronization Win32 Pin
Alex Cutovoi3-Jul-07 5:26
Alex Cutovoi3-Jul-07 5:26 
Hi for all

I've created a program that triggers some threads.
I don't get to use the syncronization. Some threads are triggered before others.

I created a class called ResourceObject. This is a simple class with a boolean value and a CRITICAL_SECTION value:
<br />
ResourceObject::ResourceObject()<br />
{<br />
   m_bLocked = false;<br />
   InitializeCriticalSection(&m_ResourceSection);<br />
}<br />
ResourceObject::~ResourceObject()<br />
{<br />
   DeleteCriticalSection(&m_ResourceSection);<br />
}<br />
<br />
void ResourceObject::LockResource(unsigned int uiTimeToSleep)<br />
{<br />
   EnterCriticalSection(&m_ResourceSection);<br />
      m_bLocked = true;<br />
	  Sleep(uiTimeToSleep);<br />
   LeaveCriticalSection(&m_ResourceSection);<br />
}<br />
<br />
void ResourceObject::ReleaseResource()<br />
{<br />
   EnterCriticalSection(&m_ResourceSection);<br />
      if(m_bLocked)m_bLocked = false;<br />
   LeaveCriticalSection(&m_ResourceSection);<br />
}<br />



In another class I have this struct that have a pointer to a ResourceObject
<br />
typedef struct LineText<br />
{<br />
   FloatText * Line;<br />
   bool bShow;<br />
   float fTimeWait;<br />
   ResourceObject * resource;<br />
}TextLine;<br />

In the same class I have the following codes:
- the first is how I create a thread;
<br />
	  idThread[m_iLineCount] = CreateThread(NULL, 0, Helper::TextThread, (void*)&Lines[m_iLineCount], CREATE_SUSPENDED, NULL);<br />


- the second is the thread:
<br />
DWORD WINAPI Helper::TextThread(void * vData)<br />
{<br />
   LineText * temp = (LineText *)vData;<br />
   temp->resource->LockResource(2000);<br />
   temp->bShow = true;<br />
   temp->resource->ReleaseResource();<br />
   return 0;<br />
}<br />


- the third is when I Resume the threads and show some text;
<br />
void Helper::ShowImages()<br />
{<br />
   for(int i = 0 ; i < m_iLineCount ; i++)<br />
   {<br />
      ResumeThread(idThread[i]);<br />
      if(Lines[i].bShow)Lines[i].Line->PrintText();<br />
   }<br />
}<br />


The threads must have to follow the sequence in that they are resumed, but they don't. Even the first thread is started with the resource, it is not the first to show the text.
Anyone can help me to solve this problem?


Thanks
AnswerRe: Thread syncronization Win32 Pin
Matthew Faithfull3-Jul-07 6:08
Matthew Faithfull3-Jul-07 6:08 
AnswerRe: Thread syncronization Win32 Pin
led mike3-Jul-07 6:19
led mike3-Jul-07 6:19 
GeneralRe: Thread syncronization Win32 Pin
Alex Cutovoi3-Jul-07 6:46
Alex Cutovoi3-Jul-07 6:46 
GeneralRe: Thread syncronization Win32 Pin
led mike3-Jul-07 8:26
led mike3-Jul-07 8:26 
GeneralRe: Thread syncronization Win32 Pin
Alex Cutovoi5-Jul-07 6:53
Alex Cutovoi5-Jul-07 6:53 
GeneralRe: Thread syncronization Win32 Pin
led mike5-Jul-07 7:17
led mike5-Jul-07 7:17 
GeneralRe: Thread syncronization Win32 Pin
Alex Cutovoi5-Jul-07 11:29
Alex Cutovoi5-Jul-07 11:29 
QuestionGraphic control on CFormView Pin
kcselvaraj3-Jul-07 5:05
kcselvaraj3-Jul-07 5:05 
AnswerRe: Graphic control on CFormView Pin
Mark Salsbery3-Jul-07 8:10
Mark Salsbery3-Jul-07 8:10 
GeneralRe: Graphic control on CFormView [modified] Pin
kcselvaraj3-Jul-07 10:14
kcselvaraj3-Jul-07 10:14 
Questionerrors on linking for *.def file Options Pin
A7Zulu3-Jul-07 4:30
A7Zulu3-Jul-07 4:30 
AnswerRe: errors on linking for *.def file Options Pin
Iain Clarke, Warrior Programmer3-Jul-07 5:53
Iain Clarke, Warrior Programmer3-Jul-07 5:53 
QuestionGeneric USB access Pin
legit3-Jul-07 4:08
legit3-Jul-07 4:08 
AnswerRe: Generic USB access Pin
CPallini3-Jul-07 4:17
mveCPallini3-Jul-07 4:17 
QuestionNeed Links of Microsoft Windows NT architecture for reading Pin
Neeranjan3-Jul-07 4:01
Neeranjan3-Jul-07 4:01 
AnswerRe: Need Links of Microsoft Windows NT architecture for reading [modified] Pin
led mike3-Jul-07 4:56
led mike3-Jul-07 4:56 
AnswerHave you heard of Google? Pin
leckey3-Jul-07 7:59
leckey3-Jul-07 7:59 

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.