# Explain the concept of semaphore. How does this help us in solving the shared data problem in embedded system?

382 views

A semaphore is called binary semaphore when its value is 0, it is assumed that it has been taken (or accepted) & when its value is 1, it is assumed that it has been released & no task has taken it yet.
An ISR can release the token. A task can release the token as well accept the token or wait for taking the token.

Shared data problem solutions:

One solution is atomic queue operation for solving the shared data problem.
1.Use modifier volatile with a declaration for a variable that returns from the interrupt. This declaration warns the compiler that certain variables can modify because the ISR does not consider the fact that the variable is also shared with a calling function.
2.Use reentrant functions with atomic function instructions in that part of a junction that needs its complete execution before it can be interrupted.
3.Put a shared in a critical queue. A function that requires the value of this variable always deletes it from the queue front, and another function, which inserts the value of this variable. always does so at the queue back.
4.Disable the interrupts before a critical section starts executing & enable the interrupts on its completion it is a powerful drastic option. An interrupt even is of higher priority than the present critical function gets disabled.

Shared-Data Problems
{
:
vconterErrors(9);
:
}
{
:
vcontErrors(11);
:
}
static int cErrors;

{
}

The above fig shows a bug in the code. Here both task1 and task2 call vcontErrors. This is a perfectly valid thing to do in an RTOS. Any or all of the tasks can share as many subroutines as is convenient.
The difficulty with the program is that because both Task1 and Task2 call vcontErrors and since vcontErrors uses the variable cErrors is now shared by the 2 tasks.
If task1 calls vcontErrors, and if the RTOS then stops Task1 and runs Task2 which then calls vcontErrors, the variable cErrors may get corrupted in just the same way as it would if Task2 were an interrupt routine that had interrupted Task1.

Reentrancy:
Reentrant functions are functions that can be called by more than one task and that will always work correctly, even if the RTOS switches from one task to another in the middle of executing the function.
The 3 rules to decide if a function is reentrant are:
1. A reentrant function may not use variables in a nonatomic way unless they are stored on the stack of the task that called the function or are otherwise the private variables of that task that called the function or are otherwise the private variables of that task.
2. A reentrant function may not call any other functions that are not themselves reentrant.
3. A reentrant function may does not use the hardware in a nonatomic way.

## Related Questions

What are counting semaphores and resource semaphore?
Last Answer : If a task tries to take the semaphore when the integer is equal to zero, then the task will block. These semaphores are called counting semaphore. Some system offer semaphore that can be ... , but they cannot be used to communicate between two tasks. Such semaphores are called resource semaphore.

Last Answer : Common computation models: Sequential program model Statements, rules for composing statements, semantics for executing them Communicating process model ... Object-oriented model For breaking complex software into simpler, well-defined pieces

Last Answer : Various features of Linux that are used in embedded systems are as follows : Linux is multiuser operating system. Linux is open source and free. Linux can be ... Linux supports handling of errors. Real-time Linux supports the group scheduling functions.

Last Answer : Liquid Crystal Display:-An LCD is a low-cost, low power device capable of displaying text and images. LCD's are extremely common in embedded systems since such system often does not have video monitors ... toggles the enables bit and acts as a delay so that the command can be processed and executed.

Last Answer : The main characteristics of an embedded system are:1. Single functioned2. Tightly constrained3. Reactive and real time1. Single functioned:An embedded system usually executes a specific program repeatedly.Ex. Pager ... computer user. But it doesn't result in a system failure.Ex. Digital camera chip

Define embedded system.
Last Answer : An embedded system is nearly any computing system other than a desktop computer. Embedded systems are hard to define because they cover such a broad range of electronic devices. It has three main components: 1. Hardware 2. Main application software 3. Real time operating system

Last Answer : Shared memory :For sharing of data faster and communication between programs, we use shared memory. Shared memory can be used with multiprocessors and single processors. Means Program ... No resource preemption4. Circular waitIf the four conditions occur simultaneously then the deadlock occurs.

What is meant by embedded Linux?
Last Answer : Linux is the operating system if we use this operating system in embedded system devices then it is known as embedded Linux. Linux is open source and free.

There are three processes P1, P2 and P3 sharing a semaphore for synchronising a variable. Initial value of semaphore is one. Assume that negative value of semaphore tells us how many processes are waiting in queue. Processes access ... The final value of semaphore will be: (1) 0 (2) 1 (3) -1 (4) -2

What is a semaphore?
Last Answer : A resource management, synchronization, and locking tool.

State the methods of task synchronization. Describe semaphore with suitable example.
Last Answer : The methods of task synchronization are: Semaphore Message queue. Mutual exclusion.  Dead lock. Mailboxes. Message Queues. Semaphores: It is a system of sending message by using flags. Multiple concurrent threads of execution ...   signal(Sem);  }  in process P2  {  wait(Sem);  S2;  }

An intuitive manager could best be described as one who: A)uses scientific problem solving B)eliminates uncertainty in decision making C)searches out facts and data systematically D)uses an orderly approach to gathering information E)uses personal knowledge and experience to make decisions
Last Answer : E)uses personal knowledge and experience to make decisions

Explain data transfer mechanism in I2C protocol. Compare it with CAN and USB protocol based on bit rate and area of applications.
Last Answer : I2C (Inter-Integrated Circuit): I2C stands for Inter-Integrated Circuit. I2C is a serial protocol. It was developed by Philips Semiconductor. I2C bus have two communication lines. One is serial data ( ... Mbps this is used for lower speed devices. Using USB we can connect upto 127 devices.

The following were the features of the Nation state that emerged in Europe in the 20th century. a. The concept and practices of a modern state with sovereign centralised power developed in Europe. ... identified their nations. Mainly female figures were used to portray the nation. d. None of these
Last Answer : b. Nation state was supposed to be a state where majority of its citizens shared common identify and history.

Firms that truly adopt the marketing concept develop a distinct organisational culture based on a shared set of beliefs that make __________ the pivotal point of the firm's decisions ... beating competitors B)increasing market share C)customers' needs D)marketing implementation E)marketing control

How did underground railway help in solving housing problem ? -SST 10th
Last Answer : London Underground partially solved the housing crisis by carrying large masses of people to and fro the city.

A transgenic food crop which may help in solving the problem of night blindness in developing countries is (a) Bt soybean (b) Golden rice (c) Flavr Savr tomatoes (d) Starlink maize.
Last Answer : b) Golden rice

Pickup wrong definition 1) Off line - is a system peripheral equipment not controlled by CPU 2) Online - is system in which peripheral equipment is in direct contact with CPU 3) PL/I is the ... /Index 4) Program or routine is a set sequence of instructions given to computer for problem solving
Last Answer : 3) PL/I is the acronym Peripheral Listing /Index

A 10-bus power system consists of four generator buses indexed as G1, G2, G3, G4 and six load buses indexed as L2, L2, L3, L4, L5, L6. The generator-bus G1 is connected ... of non linear equations required for solving the load flow problem using Newton-Raphson method in popular form is________.

Language is best thought of as Options: A) A biological (instinctive) development B) A system of symbols for effective problem-solving C) A nomenclature for cataloguing experience D) A medium for self-enhancement
Last Answer : C) A nomenclature for cataloguing experience

…………… can be defined as most recent and perhaps the most comprehensive technique for solving computer problems. A) System Analysis B) System Data C) System Procedure D) System Record
Last Answer : A) System Analysis

What sort of problem solving do you do every day?
Last Answer : This question could be answered many ways. For me it is dealing with Bipolar. Simply because some days I battle to function. More importantly though, it is the shit my illness causes. Like when I simply ... precious now. I've learned a lot from this illness. Oddly I wouldn't change a thing! :)

Which version of problem-solving method should I choose to keep my self-esteem due to almost-discovered lies?
Last Answer : answer:Which version should you choose? Do what you think is right.

Did you hear anything about the space station having something to do with solving the problem of future radiation meltdowns?
Last Answer : No, the space station could not divert radiation. No possible way it could do that.

How good at problem-solving are you (scenarios inside)?
Last Answer : answer:1. Get off the bus and call for a ride. 2. Hunker down and bust out my emergency kit, light some flares and wait for someone to drive by. A lot of this depends on where you've broken down. The ... for it. No one ever got out of a bad situation by freaking out, you have to think of a solution.

What are some math applications and problem solving practice questions websites are pretty good to use to get ready for the CPT(college placement testing)
Last Answer : I am not familiar with any websites, but Kaplan and Barron both publish excellent test prep books for most college placement tests. These books usually come with cd's with problems and your local public ... public library doesn't, an academic library (local college or high school) might have a copy.

What are the five stages in the Ladder of Problem Solving from "Thinking through Problem Solving"?
Last Answer : answer:http://www.changethis.com/21.ThinkingThrough The five stages: detection, inclination, capability, inquiry, skilled-response, and directed response. I know that's six. Maybe you only use one or the other of the last two?

What's your weirdest approach to problem solving?
Last Answer : Put in an earbud and figure it out as you go

Irrigation is very necessary for solving the food problem. -SST 10th
Last Answer : Agricultural crops are varied. Ample supply of water is required during the period of growth.

The probability of A, B, C solving a problem are 1/3, 2/7 and 3/8 respectively. -Maths 9th
Last Answer : Let E1, E2, E3 be the eventsthat the problem issolved by A, B, C respectively and let p1, p2, p3 be corresponding probabilities. Then,p1 = P(E1) = $$rac{1}{3}$$, p2 = P(E2) = $$rac{2}{7}$$, p3 = P(E3) = $$rac{3}{8}$$ ... }{8}\) = $$rac{25}{168}$$ + $$rac{5}{42}$$ + $$rac{5}{28}$$ = $$rac{25}{56}.$$

A problem in mathematics is given to four students A, B, C and D. Their chances of solving the problem -Maths 9th
Last Answer : Given, P(A) = $$rac{1}{2}$$ ⇒ P($$\bar{A}$$) = P(A not solving the problem) = 1 - $$rac{1}{2}$$ = $$rac{1}{2}$$P(B) = $$rac{1}{3}$$ ⇒ P($$\bar{B}$$) = 1 - $$rac{1}{3}$$ = $$rac{2}{3}$$P(C) = \ ... 3}{4}\)x $$rac{4}{5}$$ = $$rac{1}{5}$$∴ P(problem will be solved) = 1 - $$rac{1}{5}$$ = $$rac{4}{5}$$.

Problem solving
Last Answer : People crossed the bridge in groups of 2 and 3, Twenty one people crossed, How many groups of 2 were there, How many of 3?

What thinking skills include creative thinking making decisions problem solving seeing things in the mind's eye and which other skill?

Is a form of problem solving in which the organism develops a sudden understanding of a problem's solution.?

What are the benefits of using mental models during problem solving?

When did Alan Turing prove that a machine capable of processing a stream 1s and 0s of would be capable of solving any problem.?

What is the academic discipline that relies most heavily on algorithms for problem solving?

In the seven military problem solving process you have identified the problem. what is the next step?

Who can utilize technological design as a method to solving problem?

In the method of problem-solving, a committee is set up to find a solution. (True/False)

The component of an ICAI (Intelligent Computer Assisted Instruction) presenting information to the student is the? a) Student model b) Problem solving expertise c) Tutoring module d) All of the mentioned
Last Answer : c) Tutoring module

A plan that describe how to take actions in levels of increasing refinement and specificity is ____________ a) Problem solving b) Planning c) Non-hierarchical plan d) Hierarchical plan
Last Answer : d) Hierarchical plan

Solving a constraint satisfaction problem on a finite domain is an/a ___________ problem with respect to the domain size. a) P complete b) NP complete c) NP hard
Last Answer : b) NP complete

What is the major component/components for measuring the performance of problem solving? a) Completeness b) Optimality c) Time and Space complexity d) All of the mentioned
Last Answer : d) All of the mentioned

Web Crawler is a/an ____________ a) Intelligent goal-based agent b) Problem-solving agent
Last Answer : a) Intelligent goal-based agent

A problem solving approach works well for ______________ a) 8-Puzzle problem b) 8-queen problem c) Finding a optimal path from a given source to a destination d) Mars Hover (Robot Navigation)

The problem-solving agent with several immediate options of unknown value can decide what to do by just examining different possible sequences of actions that lead to states of known value, and then choosing the ... . This process of looking for such a sequence is called Search. a) True b) False

What is the main task of a problem-solving agent? a) Solve the given problem and reach to goal b) To find out which sequence of action will get it to the goal state c) All of the mentioned d) None of the mentioned
Last Answer : c) All of the mentioned