Jump to content
  • Advertisement
Sign in to follow this  
Prozak

Thread Inter-Syncronization

This topic is 4497 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

Ok, here is my problem: - A is a Socket Data Receiving Thread - B is processing Data, and Sending it out to a Client - A must signal B that data has arrived - B is allways alive, so geting some sort of signal from A is relatively simple using some sort of Mutex or something - Problem comes when 1) A must know that B has processed its data and 2) A cannot continue until B as processed its data. But I do not want to have A busy waiting for B, I would like to find a way to block the A thread, have a blocking wait, instead of a busy wait, where A sits in a loop asking "has B processed the data, can I continue?". Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Use a semaphore, or implement something like:


bool waitBool(bool evaluate)
{
while (!evaluate)
{
Thread::yield();
}
};


Where Thread::yield is a function that sleeps the current thread.

Share this post


Link to post
Share on other sites
Ok, but I don't want to have the thread suspended, because then, who would wake it up?

And I really didn't want to go into a sleep/check cycle, because that is too granular...

Blocking is pretty much what I'm looking for here...

Share this post


Link to post
Share on other sites
Hi,

Are you on a windows system? If you are, then I would recommend asynchronous I/O or I/O Completion ports... MSDN has good articles on them...

If you're not, have a look at the boost thread library.. they have some good synch objects... They have one that is really good that I used to help with the reader/writer problem that you are describing...

Share this post


Link to post
Share on other sites
Quote:
Original post by vetroXL
Hi,

Are you on a windows system? If you are, then I would recommend asynchronous I/O or I/O Completion ports... MSDN has good articles on them...

If you're not, have a look at the boost thread library.. they have some good synch objects... They have one that is really good that I used to help with the reader/writer problem that you are describing...


Thanks for the reply.

Yes, this is a Windows 2000/XP Project, and also for PDAs (WinCE). I really don't have the time nor the energy to go into boost for this, and any solution I find must work on both platforms...

@kuphryn: Could you please elaborate? Where would GDNet be without single-word replies...

Share this post


Link to post
Share on other sites
Ahh, well then Boost is out of the question if you're on a PDA system... I would recomend looking up Asynchrousouse I/O or I/O Completion ports.. you'll have to decide which one works best for you situation... but they both have built in notification schemes to help with synch issues...

I use I/O completion ports if I have to build a large scalable server... but Asycnh I/o is fine if you have less then 64 simultaneous clients (sp) or if you writting a client.

Share this post


Link to post
Share on other sites
Quote:
Original post by vetroXL
Ahh, well then Boost is out of the question if you're on a PDA system... I would recomend looking up Asynchrousouse I/O or I/O Completion ports.. you'll have to decide which one works best for you situation... but they both have built in notification schemes to help with synch issues...

I use I/O completion ports if I have to build a large scalable server... but Asycnh I/o is fine if you have less then 64 simultaneous clients (sp) or if you want a client.


Nope, not a solution either, I've already built a whole system around this design, so I'm not going to go in another direction at the first sight of trouble, eheh...

I just need a way to block A, and have B unblock A.

Share this post


Link to post
Share on other sites
Well, as you know I've just completed the threaded part of my resource loader, and it uses Boost::Condition for exactly what you want.

If you're not willing to use Boost for this, you can always see how they've implemented it. The Boost::Thread library seems pretty small, so it shouldn't be that hard.

Other than that, the term you need to search for is 'conditional variable'.

Share this post


Link to post
Share on other sites
wow! tough customer ;)

Have tried an event based system like this?

Lock( DWORD dwTimeWait = INFINITE )
{
WaitForSingleObject( m_hLock, dwTimeWait );
ResetEvent( m_hLock );
}

UnLock()
{
SetEvent( m_hLock );
}

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!