Multy Thread

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an application which run more than one thread at the sametime.
All those thread call same function (output function). How I lock this
function for other thread while one thread already use it.
in C# I done it by :
void output (String ff)
{
lock(this)
{
........
}
}

How to do that in VC++.Net ?
 
I have an application which run more than one thread at the sametime.
All those thread call same function (output function). How I lock this
function for other thread while one thread already use it.
in C# I done it by :
void output (String ff)
{
lock(this)
{
........
}
}

How to do that in VC++.Net ?

You need a critical section which is created with InitializeCritcalSection()
and destroyed with DeleteCritcalSection(). On entry to your "locked" block
you call EnterCriticalSection() and on exit LeaveCriticalSection().

Regards,
Will
 
The answer to your question heavily depends on what use and you want to do.

If you are using C++/CLI that comes with VS.NET 2005, and implement managed
code, you can include <msclr\lock.h> and use the class msclr::lock. If you
are using Managed C++, you have to call the static methode Enter/TryEnter
and Exit of System::Threading::Monitor. If you are writing native code, you
have to use a Win32 API like the critical section api.

Marcus Heege
 
Back
Top