Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

Sys(2336)

This function calls the EnterCriticalSection and LeaveCriticalSection Windows API functions in a multi-threaded DLL. Added (but unsupported and undocumented) in VFP 6 SP3, this function is fully supported starting in VFP 7.

Usage

cCount = SYS( 2336 [, nAction ] )

Parameter

Value

Meaning

nAction

0 or omitted

Returns the current critical section reference count.

1

Calls the EnterCriticalSection Windows API function.

2

Calls the LeaveCriticalSection Windows API function.

3

Calls the LeaveCriticalSection Windows API function as many times as needed to reset the reference count to 0 and release the Critical Section.

cCount

Character

A character string containing the current reference count.

In a multi-threaded DLL, there may be instances where several threads need access to an exclusive resource. Calling SYS(2336, 1) enters a critical section, which prevents other threads from blocking access to that resource until SYS(2336, 2) is called to release the critical section. Since calls can be nested, you can call SYS(2336, 3) to completely bail out of a critical section (probably a great idea to put in your MTDLL’s error handler).

Help says to check out the MSDN Library Platform SDK to learn more about the EnterCriticalSection and LeaveCriticalSection API calls. We think that’s a good idea.

Example

* Start the call to the critical section.
lcCSCount = SYS(2336, 1)
*    your code here
lcCSCount = SYS(2336, 2) && Exit the critical section.

See Also

Build MTDLL, Sys()