TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abhi MFC
NA
13
0
How to use Critical Section in MFC
Jan 24 2010 3:05 PM
Hi
I have two worker threads, where one thread(WriteBuf) is writing into buffer and another thread(ReadBuf) is reading from the same buffer.
I have created CriticalSection object like CCriticalSection m_crit created globaly.
My thread code looks like below
UINT WriteBuf(LPVOID pParam)
{
crit.Lock();
buf[0] = 'a'; //Writing to buffer.
return TRUE;
}
UINT ReadBuf(LPVOID pParam)
{
buf1[0] = buf[0]; Reading from the buffer.
TRACE("%c",buf1[0]);
return TRUE;
}
Please let me know is this the rite way to lock the resource(buffer),coz i havent unlocked yet but still i can able to read the buffer from another thread(ReadBuf) .
So please help me to understand the critical section usage here.
Thanks
Abhi
Reply
Answers (
2
)
Add Menu on the MFC Dialog
Visual studio tab control, add image?