Jump to content
  • Advertisement
Sign in to follow this  
McZ

MultiThreading, win32 events

This topic is 3964 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to learn to use win32 events so I created a small test program with a mainloop that just push numbers to a queue and 2 "working" threads that pops the top number and then prints it. The problem is that I try to use an event to tell my worker threads that an object has been queued. in short I do this: 1) create worker threads 2) create event
m_Event[0] = CreateEvent(NULL,
		         true,  // TRUE=manual, FALSE=auto
			true,  // signaled state
			"QueueEvent"   // name of event; optional
			);

	if( m_Event[0] == NULL )
	{
		std::cout << "Failed to create QueueEvent." << std::endl;
	}



3) Main threads start its loop by Queueing new item and calling SetEvent(m_Event[0]); when new item is in queue. 4) Worker thread is waiting for events (I have 2 events)
while(1)
{
 DWORD e = WaitForMultipleObjects(2, m_Event, false, INFINITE);
 ResetEvent(m_Event[e]);
 ...
};



So the problem is that my worker thread only recives the first event, doesn't matter if I create the thread with manualreset flag to false the thread will only recive one event, even though my mainloop queue 10 items. EDIT: The main thread has a Sleep(1000); between each object it adds in queue.

Share this post


Link to post
Share on other sites
Advertisement
Looks fine to me at first glance. Can we see your code for adding the events to the queue?

Have you tried scattering some OutputDebugString()s about to check what's going on?

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Looks fine to me at first glance. Can we see your code for adding the events to the queue?

Have you tried scattering some OutputDebugString()s about to check what's going on?


well thanks for the help :D

When you asked I noticed I had SetEvent(&m_Event[0]);

how can I make one thread listen to one 'more-job'-event and one quit-event, and still be able to finish all jobs in a queue (if there is jobs to do).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!