Qualcomm Interview Question for Software Engineer / Developers


Country: United States




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

for simple counter variables or for bitwise ------->atomic operations are best methods.
atomic_t count=ATOMIC_INIT(0); or atomic_set(&count,0);
atomic_read(&count);
atomic_inc(&count);
atomic_dec(&count);
atomic_add(&count,10);
atomic_sub(&count,10);

spinlocks are used to hold critical section for short time and can use from interrupt context and locks can not sleep,also called busy wait loops.
fully spinlocks and reader/writer spin locks are available.
spinlock_t my_spinlock;
spin_lock_init( &my_spinlock );
spin_lock( &my_spinlock );

// critical section

spin_unlock( &my_spinlock );

Spinlock variant with local CPU interrupt disable
spin_lock_irqsave( &my_spinlock, flags );

// critical section

spin_unlock_irqrestore( &my_spinlock, flags );
if your kernel thread shares data with a bottom half,
spin_lock_bh( &my_spinlock );

// critical section

spin_unlock_bh( &my_spinlock );

if you have more readers than writers for your shared resource
Reader/writer spinlock can be used
rwlock_t my_rwlock;

rwlock_init( &my_rwlock );

write_lock( &my_rwlock );

// critical section -- can read and write

write_unlock( &my_rwlock );


read_lock( &my_rwlock );

// critical section -- can read only

read_unlock( &my_rwlock );

mutexs are used when you hold lock for longer time and if you use from process context.
DEFINE_MUTEX( my_mutex );
mutex_lock( &my_mutex );
mutex_unlock( &my_mutex );

- super star rajini kanth December 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Best sync technique?? Well, that depends upon the context. Different contexts have their own implementation and as per that one scenario can have one best in one context but not in another.

So it's totally depends upon the implementation. So, here comes the Engineering skills, what to use and where to use that, so that you can get best outcome

- Anonymous January 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Best for what?

- Anonymous December 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Yes there is no best here. Then there is no need for implementing other synchronization mechanism. So we need to understand the application.
If a common memory is shared then we can say shared memory is good idea.
Again if i need to indicate a message or signal then there is no need for shared memory to stored that message or signal.
if its send a buffer from one thread to another i can use pipeing. ...

- vijaymukilan July 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Formatting, font and signature

- Formatting, font and signature October 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As per my understanding if an interviewer ask for best synchronization
There are two
wait: ( mutex( 2.6.3 kernel ) and semaphore)
Spin : Spinlock

Now the Question arises ?when to go for wait and when to for spin
when were the critical section is more and there are delay or sleep in code then better gor for semaphore/mutex
if critical section is small and there is no delay then go for spinlock

Correct me if I am wrong

- Rajiv.D.M January 31, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

the 2 main ones are spinlock (looping until we get the resource) and mutex (sleeping untill we get the resource)

but there are implicit ways too:
- putting the synchronization code in interrupt and calling it
- putting the synchronization code in kernel and calling it
- using a queue or pipes (which are themselves syncronized)

- aviaditz February 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As stated above, there is no "best" - it all depends on the use case. You did however miss one of the most important methods, which is best if there are a lot of readers, which is RCU. Using RCU allows multiple readers to enter the critical section with no penalty at all.

- Tomer October 09, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If time bounded or critical data is required go for spinlock because it works in interrupt context once lock accuired it goes to busy wait which hamperyour time
In process context better switch to mutex which can because it can sleep and wait till resourse is free.
So Choose carefully

- Lal September 10, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

The best Synchronization technique is Shared memory

- Anonymous April 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

best synchronization techniques for accessing shared data.

- bvgr December 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Do you realize you have done nothing in answering the question about the scenarios...

- Anonymous December 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

>> Do you realize you have done nothing in answering the question about the scenarios...

Can you plz elaborate your concern here?
what scenarios are you expecting?

- bvgr January 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 vote

futex?

- manish April 13, 2013 | 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