Solved

What is several instances of the same task?

Posted on 2013-06-10
2
369 Views
Last Modified: 2013-06-10
We write C++ code for embedded controllers.  We use Keil RTL(Real Time Library) RTOS.  Our target is ARM 7 based.

In some documentation, I am reading about Semaphore Caveats.  They talk about several instances of the same task waiting for a semaphore.  What is several instances of the same task?
0
Comment
Question by:naseeam
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 39235256
You can take that expression literally. Think e.g. two or more processes that perform some computation and want to output to the same file. So in order for that not ending up in a mess, you have to sychronize output by using a semaphore, i.e. process #2 has to wait for process #1 has finished wiroting the results. This is achieved by using a synchronization object like a semaphore. The Wikipedia article explains that nicely: http://en.wikipedia.org/wiki/Semaphore_%28programming%29

Suppose a library has 10 identical study rooms, intended to be used by one student at a time. To prevent disputes, students must request a room from the front counter if they wish to make use of a study room. When a student has finished using a room, the student must return to the counter and indicate that one room has become free. If no rooms are free, students wait at the counter until someone relinquishes a room.

The clerk at the front desk does not keep track of which room is occupied or who is using it, nor does he or she know if the room is actually being used, only the number of free rooms available, which she only knows correctly if all of the students actually use their room and return them when they're done. When a student requests a room, the clerk decreases this number. When a student releases a room, the clerk increases this number. Once access to a room is granted, the room can be used for as long as desired, and so it is not possible to book rooms ahead of time.

In this scenario the front desk represents a semaphore, the rooms are the resources, and the students represent processes.
0
 
LVL 33

Assisted Solution

by:sarabande
sarabande earned 250 total points
ID: 39235482
in a multi-threaded environment 'multiple instances' of a task means that there are a number of threads each of them was performing the same (kind of) task. for example you may have 4 threads searching for a value in memory.

if each thread needs a resource which is limited (for example, you have a processor with 4 cores) and the number of threads might exceed the limit, you could use a semaphore to make sure that the number of threads executed would not exceed the limit. the others would wait on the semaphore until any of the tasks has finished and released the resource.

Sara
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

816 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

8 Experts available now in Live!

Get 1:1 Help Now