[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CriticalSection in VisaulC++ in C



In response to the item quoted below:

Win32 provides a number of synchronization methods; as noted
below, there are critical sections, mutexes, semaphores, and
events (on which one may wait). Blocking reads on both
anonymous and named (NT only) pipes can be used. Processes and
threads can wait for other processes and threads to terminate.
Files can be locked and waited upon.

There are actually 37 entries in the MSVC docs under the
heading Synchronization Functions...

Critical sections may run a factor of 10 or so faster than 
mutexes.

This stuff is pretty well covered under the VC++6.0 Platform
SDK docs.

The references are also available online at
http://msdn.microsoft.com/library/
under Platform SDK / Base Services / DLLs, Processes, and Threads /
Synchronization - just above Generic Thunks, which is another
interesting topic...

A reference I have found to be very good (i.e., all the examples
on the enclosed CD compile and run on the first try):
Win32 System Programming, by Johnson M. Hart; Addison-Wesley,
ISBN 0-201-63465-1.

Dyke
+++++++++++++++

Jim Moores wrote:
> 
> Oyvind Teig wrote:
> 
> > Dear all
> >
> > I'm porting SPoC to Microsoft Visual C++. It seems like libraries
> > as well as TIMER now function. (I need this to replace
> > the transputer plug-in board in a new product where we want
> > occam code reuse).
> >
> > It's all exclusively in the C domain. No C++.
> > In order to insert time ticks, I spawn a thread with the
> > _beginthread macro. That thread mostly sleeps, but wakes up
> > to set new time and verify front of timer queue. If a waiting
> > process is AFTER, an event flag is signalled.
> >
> > I should not have any race condition with the SPoC occam code,
> > hand-investigation "proves" this. Should I decide not to trust
> > this, would any of you know how a straight critical section
> > could be added in VC++'s C-world? In process.h I only have
> > semaphores, and I wouldn't want to semaphorize the rest of
> > SPoC. Any suggestions?
> >
> 
> >From a book I bought a couple of years ago: Windows 95 Programming Nuts
> & Bolts.  The book covers only direct Win32 calls.  It mentions (but
> provides no example uses of) three functions:
> 
> InitializeCriticalSection()
> EnterCriticalSection()
> LeaveCriticalSection()
> 
> no details of parameters or anthing though - perhaps this is what you
> are looking for?
> 
> Jim
> --
> Jim.Moores, Quickstone Systems.
> 
> >
> > --
> > Oyvind
> > (------------------------------------------------------------------(
> > )       Oyvind Teig )          oyvind.teig@xxxxxxxxxxxx ) Tel: +47 )
> > ( Navia Maritime AS (          oyvind.teig@xxxxxxxxxxxx ( 73581268 (
> > )    div. Autronica )                                   ) Fax: +47 )
> > (    7005 Trondheim (           http://www.autronica.no ( 73919320 (
> > )            Norway )                                   )          )
> > (------------------------------------------------------------------(
> > )                    http://www.autronica.no/pub/tech/rd/index.htm )
> > (------------------------------------------------------------------(

-- 
======================================================================
Dyke Stiles            >>>>>> new address!!>>> dyke.stiles@xxxxxxxxxxx
Professor and Chair, Graduate Committee
Department of Electrical and Computer Engineering
4120 Old Main Hill
Utah State University
Logan UT 84322-4120
Voice: +1-435-797-2840                          FAX:   +1-435-797-3054
Work:                http://www.engineering.usu.edu/ece/research/rtpc/
Play:  http://www.engineering.usu.edu/ece/research/rtpc/utah/utah.html
======================================================================