Solved

What is several instances of the same task?

Posted on 2013-06-10
2
371 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
[X]
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
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 34

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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
Time Machine reports 'Disc Full' 3 88
Indy 10 not Receiving UDP broadcast 3 43
Can Live bindings change TGrid Cell Colour ? 1 36
print bytes of an integer 6 28
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Windows 7 does not have the best desktop search built in. This is something Windows 7 users have struggled with. You type something in, and your search results don’t always match what you are looking for, or it doesn’t actually work at all. There ar…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.

696 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