Click here to Skip to main content
15,914,070 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow can I get the net adapter address? Pin
wangyiming22-Apr-02 19:14
wangyiming22-Apr-02 19:14 
AnswerRe: How can I get the net adapter address? Pin
Albert Pascual23-Apr-02 6:48
sitebuilderAlbert Pascual23-Apr-02 6:48 
GeneralRe: How can I get the net adapter address? Pin
wangyiming26-Apr-02 21:44
wangyiming26-Apr-02 21:44 
QuestionTabs on all my MidClients? Pin
rbc22-Apr-02 16:57
rbc22-Apr-02 16:57 
AnswerRe: Tabs on all my MidClients? Pin
l a u r e n22-Apr-02 21:19
l a u r e n22-Apr-02 21:19 
GeneralRe: Tabs on all my MidClients? Pin
rbc23-Apr-02 7:55
rbc23-Apr-02 7:55 
GeneralWebBrowser control Pin
thundercatzlair22-Apr-02 16:54
thundercatzlair22-Apr-02 16:54 
GeneralMulti-threading/multi-instances with same thread function Pin
22-Apr-02 16:51
suss22-Apr-02 16:51 
Hi, folks,

I got some problems for multi-threading/multiple instances with one thread function. What's wrong with the following code segment.

In some cases, I got wrong instance as showed below. The case is: if I have 2 jobs triggered, say Job 1 and Job 2, Job 1 is triggered first but Job 2 would be done first (i.e, done prior to Job 1). Then, when Job 2 Set event (i.e, set to signaled state), I found in Master Thread Function,
in the line of WaitForSingleObject(..), what I got is Job 1's instance and Job 1's event ? Could anyone tell me how to solve this problem ? Anything wrong ? Thanks in advance.

PS> I do need to wait for events, because I have more than one tasks to do and I need to wait until all tasks are done, although in this small code, it seems just one task.

/// JOBINST: my job instance
DWORD WINAPI StartJob( JOBINST pJobObj )
{

pJobObj->hMasterThread( 0, 0, MasterThreadFunc, pJobObj, 0, &( pJobObj->dwMasterThreadID ) );

}

DWORD WINAPI MasterThreadFunc( LPVOID lpParam )
{

JOBINST pJobObj = (JOBINST) lpParam;

pJobObj->hMailEvent = CreateEvent( 0, FALSE, FALSE, "Mail Thread Event" );

pJobObj->hMailThread = CreateThread( NULL, 0, MailThreadFunc, pJobObj, 0, &( pJobObj->dwMailThreadID ) );

WaitForSingleObject( pJobObj->hMailEvent, INFINITE );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
///<------ In some cases, I got wrong pJobObj and wrong pJobObj->hMailEvent here

CloseHandle( pJobObj->hMailEvent );

ExitThread( 0 );

}

DWORD WINAPI MailThreadFunc( LPVOID lpParam )
{
JOBINST pJobObj = (JOBINST) lpParam;

//// do something here...

//// when finished with something, set event; set to signaled state
SetEvent( pJobObj->hMailEvent );

ExitThread( 0 );

}
GeneralRe: Multi-threading/multi-instances with same thread function Pin
22-Apr-02 17:10
suss22-Apr-02 17:10 
GeneralRe: Multi-threading/multi-instances with same thread function Pin
Albert Pascual22-Apr-02 17:20
sitebuilderAlbert Pascual22-Apr-02 17:20 
GeneralRe: Multi-threading/multi-instances with same thread function Pin
22-Apr-02 17:28
suss22-Apr-02 17:28 
GeneralRe: Multi-threading/multi-instances with same thread function Pin
Albert Pascual23-Apr-02 6:26
sitebuilderAlbert Pascual23-Apr-02 6:26 
GeneralRe: Multi-threading/multi-instances with same thread function Pin
Tim Smith23-Apr-02 2:24
Tim Smith23-Apr-02 2:24 
GeneralRe: Multi-threading/multi-instances with same thread function Pin
Tim Smith23-Apr-02 2:25
Tim Smith23-Apr-02 2:25 
GeneralRe: Multi-threading/multi-instances with same thread function Pin
23-Apr-02 16:26
suss23-Apr-02 16:26 
GeneralRe: Multi-threading/multi-instances with same thread function -- I got it !! Pin
23-Apr-02 18:46
suss23-Apr-02 18:46 
GeneralUsing MSDN.... Pin
SilverShalkin22-Apr-02 16:41
SilverShalkin22-Apr-02 16:41 
GeneralRe: Using MSDN.... Pin
Paul M Watt22-Apr-02 18:55
mentorPaul M Watt22-Apr-02 18:55 
GeneralRe: Using MSDN.... Pin
Mike Nordell22-Apr-02 19:22
Mike Nordell22-Apr-02 19:22 
GeneralMSDN Pin
SilverShalkin23-Apr-02 3:01
SilverShalkin23-Apr-02 3:01 
GeneralRe: MSDN Pin
Mike Nordell23-Apr-02 10:19
Mike Nordell23-Apr-02 10:19 
QuestionHow to pass handle to stl container? Pin
Todd Smith22-Apr-02 15:37
Todd Smith22-Apr-02 15:37 
AnswerRe: How to pass handle to stl container? Pin
Paul M Watt22-Apr-02 15:52
mentorPaul M Watt22-Apr-02 15:52 
GeneralRe: How to pass handle to stl container? Pin
Christian Graus22-Apr-02 16:06
protectorChristian Graus22-Apr-02 16:06 
GeneralSpeeding Up Display Time in CEditView :: MFC Pin
valikac22-Apr-02 15:27
valikac22-Apr-02 15:27 

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.