Solved

Semaphore

Posted on 1999-01-16
2
230 Views
Last Modified: 2010-04-15
When do we have to use OpenSemaphore()???  And what will happens if my application does not use UnmapFile Viewing() and CloseHandle() atfer the application had finished? My application was able to access the Shared memory many times... but to a certain limit of continuous accessing the shared memory(about 15 mins) without using the closhandle and unmapFile Viewing(). What could be the main cause? Thanx!
0
Comment
Question by:Meng
[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 Comments
 

Author Comment

by:Meng
ID: 1258155
Please send your answers to my office account at ho_cm@gitpl.com.sg   Thanx a billion!
0
 
LVL 11

Accepted Solution

by:
alexo earned 50 total points
ID: 1258156
>> When do we have to use OpenSemaphore()?

The OpenSemaphore function enables multiple processes to open handles of the same semaphore object.  The function succeeds only if some process has already created the semaphore by using the CreateSemaphore function.

>> what will happens if my application does not use UnmapFileViewing() and CloseHandle() atfer the application had finished?

UnmapViewOfFile() is needed because although an application may close the file handle used to create a file mapping object, the system holds the corresponding file open until the last view of the file is unmapped.

When a process exits, all of the object handles opened by the process are closed.  Thus, technically it is not strictly necessary to use CloseHandle() but it is a good programming practice to do it anyway.

From KB article Q125713:

Necessity of Unmapping All Views of a Mapped File
-------------------------------------------------
 
Windows maintains an internal handle to a file mapping object for each view of that object, whether created by MapViewOfFile() or MapViewOfFileEx().  This internal handle is kept in addition to the handle returned by CreateFileMapping().  The internal handle is not closed until the view associated with the handle is unmapped by calling UnmapViewOfFile(). To completely close a file mapping object requires that all handles for the object, including internal handles, be closed.  Thus, to close a file mapping object, all views of that object must be unmapped, and the handle returned by CreateFileMapping() must be closed.
 
Extant unmapped views of a file mapping object will NOT cause a CloseHandle() on the object's handle to fail.  In other words, when your handle to the object is closed successfully, it is not necessarily true that all views have been unmapped, so the file mapping object has not necessarily been freed.
 
Failure to properly unmap all views of the object and to close the handle to the object will cause leaks in the application's paged pool, nonpaged pool, virtual bytes, and also in the system wide committed bytes.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

688 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