KNOW: Process Thread Sync Deadlock

Thread & Process

Difference Between Thread and Process

http://stackoverflow.com/questions/200469/what-is-the-difference-between-a-process-and-a-thread

A process is an instance of a program in execution. A process is an independent entity to which system resources (e.g., CPU time and memory) are allocated.

A thread exists within a process and shares the process' resources. Multiple threads within the same process will share the same heap space.

Both processes and threads are independent sequences of execution. The typical difference is that threads (of the same process) run in a shared memory space, while processes run in separate memory spaces.

Lock & Sync

Lock

In computer science, a lock is a synchronization mechanism for enforcing limits on access to a resource in an environment where there are manythreads of execution. A lock is designed to enforce a mutual exclusion concurrency control policy.

Race condition

When several processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular order in which the access takes place, it's called race condition.

Critical Section

Each process has a segment of code, called critical section, in which the process may be changing common variables, updating a table, writing a file, and so on.

The code between lock and unlock calls to a mutex.

Spinlock

Spinlock is a lock which causes a thread trying to acquire it to simply wait in a loop ("spin") while repeatedly checking if the lock is available. Since the thread remains active but is not performing a useful task, the use of such a lock is a kind of busy waiting. Once acquired, spinlocks will usually be held until they are explicitly released.

Spinlock vs. Mutex

http://stackoverflow.com/questions/5869825/when-should-one-use-a-spinlock-instead-of-mutex

Semaphore

A semaphore S is an integer variable that, apart from initialization, is accessed only through two standard atomic operations: wait() and signal().

counting semaphore: range over an unrestricted domain

binary semaphore: range only between 0 and 1

On some systems, binary semaphore are known as mutex locks, as they are locks that provide mutual exclusion.

Busy Waiting

In software engineering, busy-waiting or spinning is a technique in which a process repeatedly checks to see if a condition is true, such as whether keyboard input or a lock is available.

Deadlock

Two (or more) threads have stopped execution or are spinning permanently. For example, a simple deadlock situation: thread 1 locks lock A, thread 2 locks lock B, thread 1 wants lock B and thread 2 wants lock A.

Deadlock Requirement

1. Mutual exclusion. At least one resource must be held in a nonsharable mode; that is, only one process at a time can use the resource.

2. Hold and wait. A process must be holding at least one resource and waiting to acquire additional resources that are currently being held by other processes.

3. No preemption. Resources cannot be preempted; that is, a resource can be released only voluntarily by the process holding it, after that process has completed task.

4. Circular wait. A set{P0, P1...Pn} of waiting processes must exist such that P0 is waiting for resource hold by P1, P1 is waiting for...

Dining Philosopher

http://blog.csdn.net/b_end_an/article/details/11910651



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值