65.9K
CodeProject is changing. Read more.
Home

CObjBroker - Limited Resource Broker class

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.67/5 (2 votes)

Aug 9, 2002

1 min read

viewsIcon

40842

downloadIcon

634

If you are working with limited resources in a multithreaded scenario, ObjBroker will help you...

Sample Image - demo.gif

Introduction

Sometimes we have multithreaded scenarios and always the problem is in concurrently accessing the same resource in two threads or more. So, common solution is each resource has a lock synchronization object. But it's not good if resources to be managed are many. How about safe resource manager from threads?

Object Broker

CObjBroker is manager class to distribute limited resources to threads. Surely CObjBro have to be thread-safe. (and I hope it is) See below:

About Demo

In demo, there are two resources called 'bro1' and 'bro2' who is poor programmer ( it's me.. ) and a third thread called 'project manager' who wants to get 'bro'. 'pm1' and 'pm2 get 'bro', and keep 'bro' working until 'bro' is tired. If 'bro' is tired then release 'bro'. Last, 3rd 'pm' is good 'pm'. He gets 'bro', then he lets 'bro' rest. If 'bro' is afresh, then release for other worker 'pm's.

CBroBroker is driven from CObjBroker. And he manages 'bro's with std::list. Demo code is easy to read, so you can get an idea from CObjBroker.

I hope it helps you too. And I want your good advice and suggestion!