Solved

Need Worker Threading Example

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now