Solved

Need Worker Threading Example

Posted on 2001-08-20
2
1,093 Views
Last Modified: 2013-11-20
Can anyone provide me a sample hello world liked code that demostrate the usage of threading by using the following class :

AfxBeginThread class
CMutex
CSingle
CMultilock

thank you.
0
Comment
Question by:yccheok
[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
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 6409764
0
 
LVL 3

Expert Comment

by:GlennDean
ID: 6411732
CMutex * gpMutex = NULL;
CSingleLock * gpSingleLock = NULL;
UINT GetBufRelBufThread( LPVOID pParam );

void CSemaphoreExView::OnOptionsStartTest()
{
  gpMutex = new CMutex(FALSE);  //Not owned state
  ASSERT(gpMutex);
  gpLock = new CMySingleLock(m_pMutex,FALSE);
  ASSERT(gpLock);

  for (int i=0;i<100;i++)
  {
    AfxBeginThread(GetBufRelBufThread,NULL);
  }
}

UINT GetBufRelBufThread( LPVOID pParam )
{
  //Access some resource that needs to be protected by a lock
  gpLock->Lock();  //INFINITE wait is the default

  //CODE HERE TO ACCESS THE RESOURCE

  gpLock->Unlock();
  return 0;
}

  Glenn
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

687 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