Solved

Need Worker Threading Example

Posted on 2001-08-20
2
1,084 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
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 50
Expand data scrubbing tool 13 32
haveThree challenge 22 118
Thin secure Windows 10 5 97
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 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