mutex

A mutex blocks only the main thread when it reaches its call with the @synchronized directive

时光毁灭记忆、已成空白 提交于 2019-12-25 09:00:35
问题 I'm building a multithreaded application, from which more than one thread can write to an sqlite3 database including the main thread. I declared a static public variable to be used for the mutex: @implementation Application #pragma mark - #pragma mark Static Initializer static NSString * SubmitChangesLock = nil; + (void)initialize { [super initialize]; SubmitChangesLock = [[NSString alloc] initWithString:@"Submit-Changes-Lock"]; } + (NSString *)submitChangesLock { return SubmitChangesLock; }

wait until the previous instance of process finish

[亡魂溺海] 提交于 2019-12-25 08:04:43
问题 I am new to the world of Linux C Programming so request your patience. Found several threads about inter-process synchronization (same process but different instance) using mutex and semaphores but not exactly matching my case. I tried to follow them and tried to create few samples but none of them is working for me. Finally posting here to get some help. I am working on to create a utility which will executed over Ethernet telnet session. As noted below in USAGE comment, 1st call will pass

Periodic task concurrency issue with foreground app

风格不统一 提交于 2019-12-25 07:17:16
问题 I am developing a Windows Phone 8 app that would have a live flip tile. I will be creating a scheduled agent (periodic task not resource intensive) which will update the live tile using local data. The whole app does not connect to the internet in any way, it uses only local data. So push notifications are out of the question. I need to update the live tile from the background agent and/or from the foreground app when it's launched whichever happens first. However how can I ensure the

Periodic task concurrency issue with foreground app

无人久伴 提交于 2019-12-25 07:16:20
问题 I am developing a Windows Phone 8 app that would have a live flip tile. I will be creating a scheduled agent (periodic task not resource intensive) which will update the live tile using local data. The whole app does not connect to the internet in any way, it uses only local data. So push notifications are out of the question. I need to update the live tile from the background agent and/or from the foreground app when it's launched whichever happens first. However how can I ensure the

How to use mutex in embedded C and Atmega 16?

六月ゝ 毕业季﹏ 提交于 2019-12-25 05:33:36
问题 I am writting a C code for Atmega Microcontroller and I want to use Mutex in it. What library to include? and how to implement the code? I want this Mutex to prevent a Timer interrupt from changing a variable during a function. 回答1: If you are using an RTOS or threading library, it almost certainly includes a mutex API, and if you are not then you don't need a mutex. In any case you cannot use a mutex in an interrupt handler in any case. Instead, if your timer variable is modified in the

pthread_mutex not updating fast enough, so one thread “hogs” the lock.

[亡魂溺海] 提交于 2019-12-25 04:53:07
问题 I have a c++ program where I'm creating multiple threads and having them access a shared array. Everytime I want one thread to access the array, I call pthread_mutex_lock(&mutex); access the array and then call pthread_mutex_unlock(&mutex); All threads loop continuously until they've accessed the array a certain number of times. Thus they aren't just accessing the array once, but instead accessing it several times. Now, when I execute my program just as it is, whichever thread gets the mutex

c++ pthreads - crash while trying to lock mutex for reading

∥☆過路亽.° 提交于 2019-12-25 04:09:21
问题 Class LocalT have member of other class that realized read-write-mutex . Mutex initialized at constructor and use pthread_rwlock_rdlock(&aMutex); for reading lock. So, seems, its all ok with mutex class. But program crashed when some LocalT object lock his mutex member for reading. CSerialize.cpp:2054 line is MUTEX.lock_reading(); Thread 6 (Thread 0x80d4e00 (runnable)): #0 0x4864f11d in pthread_mutex_lock () from /lib/libpthread.so.2 #1 0x4864b558 in pthread_rwlock_init () from /lib

Multithreaded returns different result from single threaded

若如初见. 提交于 2019-12-25 04:05:55
问题 I have a problem with my code which is that the result between multi-threading and single-threaded are different. I have a function which takes an input image, and rotates in n steps around the center, and does some analysis on that image. To increase the speed of that, I rewrote the function to take as input the start angle, and end angle, and it calculates the values in between. Prototype is void rotateImageConvolution(float* image, int startMin, int startMax) Now when I call that function

Can I safely multithread something which isn't meant to be multithreaded?

我的梦境 提交于 2019-12-25 03:49:11
问题 I'm using a trait which isn't designed around multithreading (Cursive). Now, while it's using multithreading, it's going to be behind a mutex, so it won't be able to be used at two threads at the same time. What is rust trying to protect me against and can I do anything about it? For sample reference, my sample code is: extern crate cursive; use cursive::Cursive; use std::thread; use std::sync::{Mutex,Arc}; fn main() { let mut siv = Arc::new(Mutex::new(Cursive::default())); let copy_siv = siv

Why would I want to lock two mutexes in one function - that too with deferred lock?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 18:13:07
问题 https://en.cppreference.com/w/cpp/thread/lock_tag void transfer(bank_account &from, bank_account &to, int amount) { // lock both mutexes without deadlock std::lock(from.m, to.m); // make sure both already-locked mutexes are unlocked at the end of scope std::lock_guard<std::mutex> lock1(from.m, std::adopt_lock); std::lock_guard<std::mutex> lock2(to.m, std::adopt_lock); // equivalent approach: // std::unique_lock<std::mutex> lock1(from.m, std::defer_lock); // std::unique_lock<std::mutex> lock2