|
Hello,
Are you sure that CRITICAL_SECTION handles the threads waiting in FIFO order?
MSDN does not reffer to it any where
could you point me to an article or something that talks about it?
thanks
|
|
|
|
|
I misunderstood your initial question, and thought you were trying to implement a FIFO stack or similar queue.
This is what MSDN had to say about the critical section:
Platform SDK : DLLs, Processes, and Threads : Critical Section Objects ; Last updated: April 2004
"A critical section object provides synchronization similar to that provided by a mutex object, except that a critical section can be used only by the threads of a single process. Event, mutex, and semaphore objects can also be used in a single-process application, but critical section objects provide a slightly faster, more efficient mechanism for mutual-exclusion synchronization (a processor-specific test and set instruction). Like a mutex object, a critical section object can be owned by only one thread at a time, which makes it useful for protecting a shared resource from simultaneous access. There is no guarantee about the order in which threads will obtain ownership of the critical section, however, the system will be fair to all threads. Unlike a mutex object, there is no way to tell whether a critical section has been abandoned."
|
|
|
|
|
Notice,
MS does not guarantee FIFO order when using CRITICAL_SECTION:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/initializecriticalsection.asp
I've tried to implement a FIFO critical section. But i think it consumes alot of CPU time. If anyone can look into it, it would be helpfull
thanks
H FILE:
****************************
#include <windows.h>
#include <stdlib.h>
#include <list>class uFIFOCriticalSection
{
protected:
CRITICAL_SECTION _EntryCritSection;
std::list<handle> mLst_events;
public:
uFIFOCriticalSection();
void Enter();
void Leave();
virtual ~uFIFOCriticalSection();
private:
// No copies do not implement
uFIFOCriticalSection(const uFIFOCriticalSection &rhs);
uFIFOCriticalSection &operator=(const uFIFOCriticalSection &rhs);
};
****************************
CPP FILE:
**********************
#include "uFIFOCriticalSection.h"
uFIFOCriticalSection::uFIFOCriticalSection()
{
InitializeCriticalSection (&_EntryCritSection);
}
void uFIFOCriticalSection::Enter() {
EnterCriticalSection(&_EntryCritSection);
//creating an event handle for this thread (when it goes out of the critical section
HANDLE my_event = CreateEvent(NULL, false, false, NULL);
HANDLE last_event = NULL;
//checking if there is a thread inside the critical section
if (!mLst_events.empty()) last_event = mLst_events.back();
//pushing this thread's event handle into the queue
mLst_events.push_back(my_event);
LeaveCriticalSection(&_EntryCritSection);
//if there is a thread inside the, (last_event != NULL -> 'mLst_events' IS empty)
//we'll wait for the single event to be signalled.
//NOTE: if the 'last_event' is already signalled, the function will not wait
//and if the last_event is closed (by CloseHandle) the handle is invalid
//and the function will return with 'WAIT_FAILED'. Both cases are good for us.
if (last_event != NULL) WaitForSingleObject(last_event, INFINITE);
}
void uFIFOCriticalSection::Leave() {
EnterCriticalSection(&_EntryCritSection);
//the thread had left the critical section.
//getting the related event handle
HANDLE my_event = mLst_events.front();
mLst_events.pop_front();//removing myself
LeaveCriticalSection(&_EntryCritSection);
//signalling this thread's event.
//if there is a thread wait on this event,
//it's will automatically started
SetEvent(my_event);
//no need for it anymore, we can close the handle to retain resources
CloseHandle(my_event);
}
uFIFOCriticalSection::~uFIFOCriticalSection()
{
//we must release all the threads
//DO WE? let's try not...
/* std::list<handle>::iterator itr = mLst_events.begin();
while(itr != mLst_events.end()) {
SetEvent((*itr));
itr++;
}*/
DeleteCriticalSection (&_EntryCritSection);
}
*****************
|
|
|
|
|
Hi all:
Can anybody gives me a fully explanations or references of FDT(File Directory Table).
Does it has something to do with the order appearing after the DOS command "dir"?
Thanks!
|
|
|
|
|
With FAT16, and possibly FAT32, the order in which files/folders are enumerated is governed by how they were added to the FAT initially. IIRC, files/folders on NTFS are enumerated alphabetically.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanks! Then how can I retrieve the FTD for specific folder?
|
|
|
|
|
I'm not familar with FTD in the context of folders. Could you be more specific?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi,
I have to create two propertysheets at runtime in dialog box.
when i run the project i get the last property sheet with dialog box and other controls
hidden.
if i run the project commenting one propertypage and viceversa i am getting the property
page and all the controls.
after creating each property sheet i used to call the modify style function.
can you give me any suggestion.
With Regards,
R.Sundaram.
|
|
|
|
|
how to get software package for vc++ project exe
|
|
|
|
|
Are YOu looking for Some Type of Installer.
Grab it from here INNO Setup
[^].
It's FREE
"I Think this Will Help"
<h5
alok gupta="" <br=""> visit me at http://www.thisisalok.tk
|
|
|
|
|
Hello ,
I want to give the int code and get string instead.
You know that 65 is A and...
I want this function for unicode keys.
Best Wishes,
Thanks.
|
|
|
|
|
I need to do some clean up work before my MFC SDI program exits. How and where can I break into the program to do these things. I need to close a serial port in particular.
Thanks
John
|
|
|
|
|
Where is the handle of your COM port stored ? You can close the port in the destructor of the class that contains this handle for example.
Or you can override the ExitInstance from your CWinApp class and close it there.
Hope this helps
|
|
|
|
|
hi all,
I am using Text boxes to MFC Dialog base Applcation.But I can not change the Color Scroll bars which appear with TextBoxes,ListBoxes like that..
How do I do that?
if any one this pl reply me..
Thanks in advance..
|
|
|
|
|
How to call javascript in mfc project without CHtmlView?
I have a source code implement IDispatch by CHtmlView,
but in my project I don't need it.
Thanks!
|
|
|
|
|
Sounds like you need to look at Active Script Host.
onwards and upwards...
|
|
|
|
|
Hi
I am working with Win32 serial communication programming in vc++. I was asked to use sliding window method here, but I am totally new and have no idea about this sliding window consept.
Can anyone please help me by giveing me some information on sliding window and its implementation algorithm and how it can be used in serial communication.
I would be of great help to me if any one can give me some inputs.
Thanks
Madhavi
|
|
|
|
|
Try Here[^]
or
Try using google and insert "sliding window method"
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
I have a few Property pages (not Wizard). On one of these I am displaying a picture (Picture Control). The file name is in a global variable. When I initialize it, the picture is displayed correctly. If a file is loaded, I want to show the picture when the user switches between the tabs. Currently when I come back to the tab with picture it is not displaying again. I have written the following code in OnSetActive event -
<br />
if (g_strFileName != "") {<br />
CDC *dc;<br />
dc = GetDC();<br />
CPicture ppic;<br />
ppic.Load(g_strFileName);<br />
CRect rc; GetDlgItem(IDC_RECT_BITMAP)->GetWindowRect(rc);<br />
ScreenToClient(&rc);<br />
ppic.Render(dc, rc);<br />
ReleaseDC(dc);<br />
}<br />
I am also calling Invalidate(TRUE) in InitDialog. Any help would be appreciated.
I have also tried OnPaint/ InitDialog etc. No luck. Thanks.
|
|
|
|
|
1. Are you returning CPropertyPage::OnSetActive(); in from your OnSetActive() function?
I am also calling Invalidate(TRUE) in InitDialog. Any help would be appreciated.
I have also tried OnPaint/ InitDialog etc. No luck. Thanks.
--> InitDialog() function is only called once and not everytime you navigate through the tab pages. so it won;t help.
Thanks
Abhi Lahare
|
|
|
|
|
Yes, I am returning return CPropertyPage::OnSetActive();
|
|
|
|
|
Thanks Abhi for replying to my question . I somehow found a solution. I made the picture control Transparent and Simple and moved the painting code to OnPaint. Now it seems to be working perfectly fine. Still not sure what the problem was .
|
|
|
|
|
I have a semi-transparent window. I need all mouse clicks to fall through to proper windows underneath mine. I need to implement a "click-through window"
How do I do this?
|
|
|
|
|
|
HTTRANSPARENT is usefull when you create a control and you want clickthrough to the parent... However in my case I want clicks to fall through a top level window to the underlying windows.
|
|
|
|