|
Thankyou, I will have a read and if i uderstand i might try and impilment it.
Thanks again for all your help.
|
|
|
|
|
You are welcome.
All those books about the C++ Language teach STL.
For example:
- "The C++ Programming Language, 3rd Ed Gold", by Bjarne Stroustrup.
- "C++ Primer, 4th Ed", by Stanley Lippman.
- "C++ From the Ground Up, 3rd Ed", by Herbert Schildt.
etc.
There also are some STL specific books talking deep into STL.
Maxwell Chen
|
|
|
|
|
mutex1 in thread 1
mutex2 in thread 2
how to lock the two mutexes simultaneously in thread 3?
Vincent
|
|
|
|
|
You can't lock two mutexes simultaneously in Windows. You can only do them one at a time. Be careful with locking two mutexes at the same time, as it can easily lead to deadlocks.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I agree. The only way I see is for you to create a third mutex whick must be locked before accessing any of the other 2, and unlocked when the others are locked. If you try this then you will probably be on an even faster road to deadlock.
Anyway, there may be better objects for you to use instead of mutexes if you are having such a strange necessity. Can you ellaborate a little bit?
Rilhas
|
|
|
|
|
hi ,Ryan and Rilhas
the context is producer/consumer
thread1
----------------------------------------------
p(empty)
mutexRW.lock()
produce(item)
mutexRW.unlock()
v(full)
-----------------------------------------------------
thread2
----------------------------------------------
p(full)
mutexRW.lock()
comsume(item)
mutexRW.unlock()
v(empty)
-----------------------------------------------------
I need to stop thread1 and thread2 sinultaneously in thread3 to avoid deadlock at p(empty) in thread1 for buffer is full or deadlock at p(full) in thread2 for buffer is empty.
and I can't use a third mutex to achieve that because a third mutex would be unefficient for producer/consumer. so give me some clues to solve this problem please. thanks
Vincent
-- modified at 12:48 Tuesday 2nd May, 2006
|
|
|
|
|
I think I don't understand your problem exactly... what are p(x) and v(x)? Why would they cause deadlocks??
Anyway, it seems to me that the most adequate object for you would be a critical section instead of a mutex. The critical section has the benefit of being somewhat more efficient than a mutex. A critical section executes and locks in about 10 cpu cycles (if available) while a mutex locks in about 600 cpu cycles.
The critical sections also have a very nice property that allows the same thread to lock it more than once. In fact, after a thread grabs hold of a critical section object, it can lock it as often as requested and never be blocked. This is useful in the following example:
int FuncA() {
cs.Lock();
do something A
cs.UnLock()
}
int FuncB() {
cs.Lock();
do something B
cs.UnLock()
}
int FuncC() {
cs.Lock();
FuncA();
FuncB();
do something C
cs.UnLock()
}
This property may make it easier for you to avoid deadlocks, since a critical section never locks the thread that owns it. In the example above you can export FuncA(), funcB(), and also FuncC() which uses the already protected FuncA() and FuncB(), and adds a lock of its own. As mentioned, the sequence of 3 locks and unlocks is extremelly fast.
There are also some downsides to critical sections. 1) They can only be used inside the same process space, and not across processes. 2) Some users also report that critical sections do not react very well when they are destroyed if some threads are trying to lock it under Windows 95. I never had any problems. 3) They don't allow a timeout value to be specified in the 95/98/Me fmaily, and also in NT4.
I hope this helps.
Rilhas
|
|
|
|
|
Hi
my self is ravindra kumar
this is a urgent assignment for me i need a urgent help.
steps of assignment are .
1:- draw a graphics image like circle, rectanlg,square,
triangle,
2: provide aZoom in and Zoom out functionality for that image.
3: provide a rotation functionality for that image which give a 3-d roatation
how can i solve the assignment using application wizard.
or using MFC,
thanks
ravindra
Ravindra
|
|
|
|
|
I want to handle the message that mouse click the vertical scrollbar of the listctrl,and codes as below:
CMyListCtrl::public CListCtrl
BOOL CMyListCtrl::PreTranslateMessage (MSG* pMsg)
{
CScrollBar* pScroll = GetScrollBarCtrl(SB_VERT);//pScroll is NULL!!
if(NULL != pScroll && pMsg->hwnd == pScroll->GetSafeHwnd()){
BOOL flag = FALSE;
CRect rect;
pScroll->GetWindowRect(&rect);
if (pMsg->message == WM_LBUTTONDOWN){
}
}else if(pMsg->message == WM_LBUTTONUP){
}
}
}
|
|
|
|
|
Use a different approach
check out the methods : CWnd::OnVScroll and CWnd::OnHScroll on MSDN , they will help you
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
I just want to handle the message WM_LBUTTTONDOWN And WM_LBUTTONUP and not to handle the message of WM_VSCROLL
|
|
|
|
|
There are 2 types of scrollbars, one that is a scrollbar control that has it's own window handle, and one that is drawn in the non-client area of a window. Most scrollbars are of the second type, drawn in the non-client area and not a window by itself.
Handle WM_NCLBUTTONDOWN and WM_NCLBUTTONUP. You can check for the hittest value of HTVSCROLL to see if the vertical scrollbar has been clicked.
Edit: Now that I think about it, what's wrong with YaronNir's solution? Do you have to do something on mouse down and then something on mouse up and not just checking for a click?
-- modified at 7:32 Sunday 30th April, 2006
|
|
|
|
|
void CMyListCtrl::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(HTVSCROLL == nHitTest)
MessageBox("LButtonDown On Vertical Scroll");//Here is OK
CListCtrl::OnNcLButtonDown(nHitTest, point);
}
void CMyListCtrl::OnNcLButtonUp(UINT nHitTest, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(HTVSCROLL == nHitTest)
MessageBox("LButtonUp On Vertical Scroll");//No MessageBox
CListCtrl::OnNcLButtonUp(nHitTest, point);
}
how can I get the message of WM_LBUTTONUP of the Vertical Scroll Bar
|
|
|
|
|
Hi All,
I am fairly new to Visual C++ (2005). Up until now I have been using the Borland product, both Delphi & C++.
In these to environments to create read from or write to a INI file was a pretty easy process as there were classes for these already part of the Borland products.
With VC++ I am finding that there are no native classes to use to create the INI – but I will stand corrected though.
After more investigation I find that there is a push to replace the INI file with an XML file.
Is this correct ?
Are there tutorials I can read to get an understanding on how I create/write/read from these files ?
What are they called these days. With the INI file, they were just referred to as “INI Files” – what are they called these days (using XML) ?
Pete
|
|
|
|
|
Check out in MSDN the methods : WritePrivateProfileXXXXX where XXXX is the type you want to write... (strint int etc.)
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
I am not sure about VC++ 2005, but the raw APIs should still be there. As far as I know INI files are still called INI files, it is just that they where replaced by the registry when Win95 came out. It is not that you could no longer use INI files, it was just that the registry was the new and recomended way to save the same information. The raw APIs could now be used to write/read the registry or an INI file.
They seem to be wanting to replace everything with XML files, so I do not know what [all] they are doing with them at the moment.
Try looking up WriteProfileString() and see where that leads you.
Good Luck!
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
As Yaron say, WritePrivateProfileXXX is good, it will use either an INI file or the registry depends on the version of Windows. I believe now the default is the registry.
Look around on CP and there are INI file classes as well.
Elaine
The tigress is here
|
|
|
|
|
Fritzables wrote: I am fairly new to Visual C++ (2005). Up until now I have been using the Borland product, both Delphi & C++.
BTW, have you moved to VC++ 2005 as a result of Borland's recent decision to sell their IDE business?
Kevin
|
|
|
|
|
Kevin McFarlane wrote: Borland's recent decision to sell their IDE business?
I have heard this rumor for 2 years or more.
Maxwell Chen
|
|
|
|
|
Well, it's actually an official announcement now. Was the rumour of two years ago also an official announcement?
Kevin
|
|
|
|
|
|
G'Day All,
Thanks for the help on this one.
Actually I may stay with creating an INI file instead of having to change a registry setting when ever I want to change a value.
No, I didn't know Borland was getting out if the IDE side of things - very interesting indeed. Is this a recent announcement ?
Pete
|
|
|
|
|
It was announced a couple of months ago. There's various articles on BDN about it, and much discussion on the borland.cppbuilder.* groups.
If Kevin's interested in my answer to his question: I've been using C++Builder almost exclusively since version 3 came out, but I started the move to VS 2003/2005 last autumn. I won't be completing the move for several years at least, since I have many current C++Builder applications to support and many more legacy apps I'll be supporting for a long time to come. The "DevCo" announcement just made me feel better about making the change -- I'm tired of using an IDE that's always a poor stepsister to Delphi.
|
|
|
|
|
Hi
i,m ravindra new member of your team,
i, have a some problem these are.
How i can add my Zoom In and zoom out function in VC++ using MFC in 2d graphics like rectanle?
how can added rotate function in above problem which give a 3-d graphics?
it is a very urgent
ravindra
kannojia_123@rediffmail.com
-- modified at 8:21 Sunday 30th April, 2006
|
|
|
|
|
Go to the GDI section of codeproject, you will find some articles on programs that require that kind of functionality.
In order to zoom in and out you need to use the StretchBlt() function.
Something else that may come in handy is JrsCExBitmap.asp[^], which has information on 2D rotaion as well as providing an undo/redo feature to graphics editors.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|