Solved

About using "Critical Section"

Posted on 1997-07-03
2
226 Views
Last Modified: 2010-08-05
Hi,
   I want to block the system during my function using Critical Section.
   How can I use it to my function?
====================================================
void CLogFile::WriteToLog( const CString& strMsg )
{      TRY
      {
       oOut.Open(FileName.. );
       oOut.SeekToEnd();
       oOut.WriteString( strOut );
       oOut.Close();
      }
      CATCH( CFileException, e )
      {
#if defined ( _DEBUG )
      TRACE( CString( "Could not write to file " ));
#endif
      }
      END_CATCH
}
=========================================================
Thanks!!
         
0
Comment
Question by:jpchen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 2

Accepted Solution

by:
sprinkmeier earned 50 total points
ID: 1164275
If you create an instance if the ICritSect class, then you have created a critical section, ie.

foo()
{
  .....code....
  {
    ICritSect crit;
    // this code runns 'critical'
    .....
  }
  // end ccritical section
  ...
}


However, I'm not sure this is what you want. Critical secitons only disable other threads in a given progcess, I'm not sure of how to disable "the system" (I assume you mean the kernel).
You could try boosting your priority to 'slow-down' the rest of the system (yuck!), or a shared mutex sem to stop cooperating processes.
BEWARE!! MUTEX semaphores and critical sections do not mix well, all but the most trivial examples are prone to all sorts of deadlocks.

(tell me if you need the C API calls for the above. bit rusty on those...)
0
 
LVL 2

Expert Comment

by:sprinkmeier
ID: 1164276
Me again...
You did not specify a platform/OS, and I assumed OS/2 (cos that's what I know).

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question