mutual-exclusion

If mutual exclusion is guaranteed, say with semaphores, is a program deadlock-free?

蹲街弑〆低调 提交于 2019-12-07 04:11:11
问题 I define mutual exclusion and deadlock as below, respectively: The mutual exclusion condition exists if at every moment, each shared resource is either assigned to exactly one process, or available. A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause. Say, binary semaphores are used, ensuring that only one of them can enter its critical region at the same time. Since each process does a down just before entering

What is equivalent of the C# lock statement in PHP?

自闭症网瘾萝莉.ら 提交于 2019-12-05 19:24:17
For concurrency and ensuring the integrity of the data, how would you obtain a mutual-exclusion lock for a given object? Would you need to use locking within the database, or a file, or does PHP support something like this? PHP doesn't support multithreading so there's no locking mechanism for objects. If you want to lock a file you could use flock for that. There's no need to lock database as database engines usually can handle multiple connections. Bare in mind PHP is not multithreaded, so it's unlikely you need anything like this... however, may be needed if you use shared memory, or any

If mutual exclusion is guaranteed, say with semaphores, is a program deadlock-free?

江枫思渺然 提交于 2019-12-05 10:28:43
I define mutual exclusion and deadlock as below, respectively: The mutual exclusion condition exists if at every moment, each shared resource is either assigned to exactly one process, or available. A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause. Say, binary semaphores are used, ensuring that only one of them can enter its critical region at the same time. Since each process does a down just before entering its critical region and an up just after leaving it, mutual exclusion is guaranteed. I understand there

Making pthread_rwlock_wrlock recursive

依然范特西╮ 提交于 2019-12-05 08:43:19
I have a problem regarding the behaviour of the pthread function pthread_rwlock_wrlock . The specification linked above states that when one thread has locked the lock for writing and the same thread locks it again, it results in undefined behaviour (I could actually observe this in that on x86 Linux calling this function is a noop and on PowerPC Linux it stalls the thread). The behaviour I need would be a read write lock that has the following characteristics: read-locking by a thread succeeds if: the lock is not held by any thread the lock is only read-locked by zero or more threads

What's the best linux kernel locking mechanism for a specific scenario

北城以北 提交于 2019-12-04 13:34:12
问题 I need to solve a locking problem for this scenario: A multi CPU system. All of the CPU's use a common (software) resource. Read only access to the resource is very common. (Processing of incoming network packets) Write access is a lot less frequent. (Pretty much configuration changes only). Currently I use the read_lock_bh , write_lock_bh (spinlocks) mechanism. The problem is that the more CPU's, the more I get soft lockups in a writer context. I read the concurrency chapter in this book,

Mutex alternatives in swift

断了今生、忘了曾经 提交于 2019-12-04 10:12:56
问题 I have a shared-memory between multiple threads. I want to prevent these threads access this piece of memory at a same time. (like producer-consumer problem) Problem : A thread add elements to a queue and another thread reads these elements and delete them. They shouldn't access the queue simultaneously. One solution to this problem is to use Mutex. As I found, there is no Mutex in Swift. Is there any alternatives in Swift? 回答1: As people commented (incl. me), there are several ways to

Bounded-waiting Mutual Exclusion with test and set

為{幸葍}努か 提交于 2019-12-03 09:57:31
问题 I am reading the famous Operating System Concepts book of (Avi Silberschatz, Peter Baer Galvin, Greg Gagne) edition 9: http://codex.cs.yale.edu/avi/os-book/OS9/ In the process synchronization chapter, there is an algorithm for "Bounded-waiting Mutual Exclusion with test_and_set" as follow: do { waiting[i] = true; key = true; // <-- Boolean variable that I do not see its utility while (waiting[i] && key) // <-- the value of the key variable here is always true key = test_and_set(&lock); // <--

What's the best linux kernel locking mechanism for a specific scenario

六眼飞鱼酱① 提交于 2019-12-03 07:44:57
I need to solve a locking problem for this scenario: A multi CPU system. All of the CPU's use a common (software) resource. Read only access to the resource is very common. (Processing of incoming network packets) Write access is a lot less frequent. (Pretty much configuration changes only). Currently I use the read_lock_bh , write_lock_bh (spinlocks) mechanism. The problem is that the more CPU's, the more I get soft lockups in a writer context. I read the concurrency chapter in this book , But couldn't quite understand whether the reader or the writer will get priority when using spin locks.

Mutex alternatives in swift

岁酱吖の 提交于 2019-12-03 05:20:39
I have a shared-memory between multiple threads. I want to prevent these threads access this piece of memory at a same time. (like producer-consumer problem) Problem : A thread add elements to a queue and another thread reads these elements and delete them. They shouldn't access the queue simultaneously. One solution to this problem is to use Mutex. As I found, there is no Mutex in Swift. Is there any alternatives in Swift? As people commented (incl. me), there are several ways to achieve this kind of lock. But I think dispatch semaphore is better than others because it seems to have the least

Implementing Mutual Exclusion Algorithm by Burns and Lynch in Java: Could there be issues due to instruction reordering?

谁说我不能喝 提交于 2019-12-02 09:52:39
I found a fairly simple n-process mutual exclusion algorithm on page 4 (836) in the following paper: "Mutual Exclusion Using Indivisible Reads and Writes" by Burns and Lynch program Process_i; type flag = (down, up); shared var F : array [1..N] of flag; var j : 1..N; begin while true do begin 1: F[i] := down; 2: remainder; (* remainder region *) 3: F[i] := down; 4: for j := 1 to i-1 do if F[j] = up then goto 3; 5: F[i] := up; 6: for j := 1 to i-1 do if F[j] = up then goto 3; 7: for j := i+1 to N do if F[j] = up then goto 7; 8: critical; (* critical region *) end end. I like it, because of its