Both manage a limited resource. I'll first describe difference between binary semaphore (mutex) and spin lock.
Spin locks perform a busy wait - i.e. it keeps running loop(In turn heavy CPU usage example is
in Reactor usage of AsyncTaskExecutors):
It performs very lightweight locking/unlocking but if the locking thread will be preempted by other which will try to access the same resouce the second one will simply try to acquitre resource untill it run out of it CPU quanta.
On the other hand mutex behave more like:
Hence if the thread will try to acquire blocked resource it will be suspended till it will be avaible for it. Locking/unlocking is much more heavy but the waiting is 'free' and 'fair'.
Semaphore is a lock that is allowed to be used multiple (known from initialization) number of times - for example 3 threads are allowed to simultainusly hold the resource but no more. It is used for example in producer/consumer problem or in general in queues:
|
In this series I would be covering the basic operation of GIT so that even a new comer can easily feel comfortable with the terminologies and usage of git system. The first post is just a brief introduction that will help you clarify the questions raising about this new thing. What is a Git? Git is simply a software that helps you manage your source code.That means each change that you make to a source code is recorded in its history.So it can also be called as Source Code managemnt system. To use git for a particular project all you need is to initialize the current project folder so that it will be tacked by the git system.I will show it in further documents about how to do it. Every Git working directory(or you can say your project folder) is a full-fledged repository with complete history and full version tracking capabilities, not dependent on network access or a central server. What is GitHub ? In layman terms you can think ...
Can you please explain the difference between waiting threads and suspended threads?
ReplyDeleteI mean both are waiting in the end..we are not able to use them?
It doesn't mean much of a difference.The only thing in depending on programming language there's a little variance. Wait basically means your thread is active and actively using your CPU cycles waiting on some conditions.Suspended means your thread context is saved and currently your thread is dormant and not burning off CPU cycles.
Delete