Samsung Interview Question for Applications Developers


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
3
of 3 vote

This is a shared resource management problem which is typically resolved using counting semaphores. Please note the difference from mutex, semaphores are shared by multiple processes, mutexes are not. And mutxes are like binary semaphore: they are either locked or unlocked and can be in no other state. But a counting semaphore can have any number of counts.

You would start the write semaphore at the count of 2, and start the read semaphore at the count of one.

Each process, when it needs to write to the file, will wait on the semaphore. If the count is less than one, the process is put in a waiting queue and wait for some other process to signal the semaphore. If the count is large then one, the count is reduced by one and the process then proceeds to access the resource. When it is done accessing the resource, it then signals the semaphore, meaning the count is increased by one, so that other processed in the waiting queue can then proceed.

Same happens to the read process. It wait on the semaphore, access the resource, and then signals the semaphore when done.

- Anthony Mai February 05, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can the read and write happen at same time?

- Anonymous February 08, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can the read and write happen at same time?

- Anonymous February 08, 2016 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More