Solved

What is several instances of the same task?

Posted on 2013-06-10
2
365 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 32

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
Windows 10 is here and for most admins this means frustration and challenges getting that first working Windows 10 image. As in my previous sysprep articles, I've put together a simple help guide to get you through this process. The aim is to achiev…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

743 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

15 Experts available now in Live!

Get 1:1 Help Now