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
Solved

Need Worker Threading Example

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 65
mixString challenge 36 131
Question regarding Copy/Paste 16 96
while loop over for loop 7 115
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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