[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

What is several instances of the same task?

Posted on 2013-06-10
2
Medium Priority
?
377 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 1000 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 35

Assisted Solution

by:sarabande
sarabande earned 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

649 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