Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

Multy Thread

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
[Yosi] - 08 Jun 2005 08:28 GMT
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 ?
William DePalo [MVP VC++] - 08 Jun 2005 15:09 GMT
>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
[quoted text clipped - 9 lines]
>
> 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
Marcus Heege - 08 Jun 2005 18:38 GMT
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

>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
[quoted text clipped - 9 lines]
>
> How to do that in VC++.Net ?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.