Begin/EndCriticalRegion

  • Thread starter Thread starter Moshe Peleg
  • Start date Start date
M

Moshe Peleg

Hi,

Is there any replacement for these function on the CF2?

I have a critical code in a high prioirity thread that I want to finishe
executing without the interruption of other
threads.

Thanks.
 
CriticalRegions are used for determining behavior when a thread abort or an
unhandled exception occurs. That doesn't sound like what you want.

Monitor.Enter/Exit might be what you need, but it simply prevents 2 threads
from running the same piece of code at the same time (like a
CRITICAL_SECTION in native code). That also doesn't really sound like what
you want based on your description.

I *think* (and again, your requirement is a little unclear) what you want is
to simply increase the priority of your "critical" thread so it can't be
pre-empted by another thread. If it's a long-running thread, altering the
quantum might be useful as well (though not nearly as simple as changing the
priority).


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
Hi and thank you for your answers.
The thread is actually a communication thread that never ends.

The priority of this thread is set to highest.
Does it mean that lower priority threads will not interrupt until it sleep ?
 
More details:

The communication thread fills a buffer. I don't want it to be read by other
threads until I finish filling it.
 
The priority of this thread is set to highest.
Does it mean that lower priority threads will not interrupt until it sleep
?

Preempt is the term you want to use, not interrupt. In Windows CE (and in
computing in general) an interrupt is a totally different thing and using
that term is going to cause confusion.

It means the scheduler will not preempt the thread to run any lower priority
thread (unless a lower priority thread needs to be promoted to prevent an
inversion and deadlock). A same-priority thread could preempt you if your
thread takes longer than the system-defined quantum period (50ms is the
default in CE).


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
The best way to do that would be to protect the data item, *not* control the
priority of the thread doing the filling. Using a mutex seems like the best
way to achieve that. It would also protect you in the other direction, so
that your 'filler' thread doesn't start writing the buffer again, while some
other thread is reading it.

In answer to your other message, it's not clear what Highest actually
corresponds to at the operating system level. If it should happen to
correspond to a thread priority of 0 at the OS level, which is very
doubtful, the thread will execute until it either exits or blocks on some OS
call. If it actually maps to some other high, but not absolutely highest,
OS priority, it will execute, when it's not blocked, as long as there is no
other ready-to-execute thread of the same or higher priority.

Paul T.
 
"Highest" is a managed enumeration member for the Thread class. I think
it's 248 (or thereabouts) so it's not really that high. Just the higest
managed code will let you set without a P/Invoke.

And I agree, he needs a thread sync object, not a priority hack.

--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com



"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
 
Back
Top