Solved

What is several instances of the same task?

Posted on 2013-06-10
2
372 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
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.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

728 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