critical-section

C++: Concurrency and destructors

前提是你 提交于 2020-02-02 04:49:57
问题 Suppose you have an object which can be accesed by many threads. A critical section is used to protect the sensitive areas. But what about the destructor? Even if I enter a critical section as soon as I enter the destructor, once the destructor has been called, is the object already invalidated? My train of thought: Say I enter the destructor, and I have to wait on the critical section because some other thread is still using it. Once he is done, I can finish destroying the object. Does this

Critical Section in JavaScript or jQuery

ⅰ亾dé卋堺 提交于 2020-01-14 07:51:08
问题 I have a webpage, in which a certain Ajax event is triggered asynchronously. This Ajax section could be called once or more than once. I do not have control over the number of times this event is triggered, nor the timing. Also, there is a certain code in that Ajax section that should run as a critical section, meaning, when it is running, no other copy of that code should be running. Here is a pseudo code: Run JavaScript or jQuery code Enter critical section that is Ajax (when a certain

Disable Hardware & Software Interrupts

扶醉桌前 提交于 2019-12-30 04:48:06
问题 Is it possible to disable all interrupts with a ASM/C/C++ program to get full control about the processor? If yes -> how? If not -> how do "atomic" operation system calls work (for example entering a critical section)? Thanks for your help! 回答1: In x86 assembly the the commands are sti set interrupt enable bit cli clear interrupt enable bit These commands set and clear the IF Flag. When the IF flag is set, the CPU will handle hardware interrupts, and when it is clear the CPU will ignore

Synchronization between threads using Critical Section

坚强是说给别人听的谎言 提交于 2019-12-25 05:31:29
问题 I have multiple threads, ThreadA and ThreadsB-Z. ThreadA is always in critical section, popping the data out of queue and sending it on socket. When any thread from ThreadB to ThreadZ want to enter the critical section, it wants ThreadA to leave critical section only then. It then enters the critical Section, push some data into queue and leaves critical section. I have two problems here: How would ThreadB-Z (whoever wants to enter the Critical Section) tell ThreadA to leave critical section

Check optional mutex before scoped locking

老子叫甜甜 提交于 2019-12-24 10:56:42
问题 I have a constructor that optionally allows the user to pass a ponter to a Boost mutex. If no mutex is supplied, the member pointer pMyMutex is set to NULL . This gives the user the option of applying some thread safety if they wish. However, I cannot use a scoped_lock with this kind of check for obvious reasons :) if (pMyMutex != NULL) const boost::mutex::scoped_lock l(*pMyMutex); //The lock is already out of scope processStuff(x, y, z); Can anyone suggest a neat and simple solution to such

Thread/warp local lock in cuda

跟風遠走 提交于 2019-12-24 09:48:13
问题 I want to implement critical sections in cuda. I read many questions and answers on this subject, and answers often involve atomicCAS and atomicExch. However, this doesn't work at warp level, since all threads in the warp acquire the same lock after the atomicCAS, leading to a deadlock. I think there is a way to have a real lock in cuda by using warp __ballot or __any instructions. However, after many attempts, I don't get to a satisfying (read working) solution. Does anyone here have a good

Multithreading and Critical Sections Use - C++

帅比萌擦擦* 提交于 2019-12-22 10:46:33
问题 I'm a little confused as to the proper use of critical sections in multithreaded applications. In my application there are several objects (some circular buffers and a serial port object) that are shared among threads. Should access of these objects always be placed within critical sections, or only at certain times? I suspect only at certain times because when I attempted to wrap each use with an EnterCriticalSection / LeaveCriticalSection I ran into what seemed to be a deadlock condition.

Critical Sections and return values in C++

北战南征 提交于 2019-12-22 04:42:15
问题 In attempting to create a thread-safe container class from scratch, I've run into the problem of returning values from access methods. For example in Windows: myNode getSomeData( ) { EnterCriticalSection(& myCritSec); myNode retobj; // fill retobj with data from structure LeaveCriticalSection(& myCritSec); return retobj; } Now I suppose that this type of method is not at all thread-safe because after the code releases the critical section another thread is able to come along and immediately

Is it safe to access VT data from the other thread?

时光总嘲笑我的痴心妄想 提交于 2019-12-21 17:52:10
问题 Is it safe to change VirtualTreeView data from the secondary thread ? And if yes, should I use critical sections (or even Synchronize method) ? I'm afraid that when I'll be writing to the VT's data record from the other thread, main thread invokes its repaint meanwhile and this refresh will cause reading of the same record at one time. I would supplement I'm using only 2 threads in the application. Something like ... type PSomeRecord = ^TSomeRecord; TSomeRecord = record SomeString: string;

How to use Multiple Variables for a lock Scope in C#

旧巷老猫 提交于 2019-12-21 09:53:11
问题 I have a situation where a block of code should be executed only if two locker objects are free. I was hoping there would be something like: lock(a,b) { // this scope is in critical region } However, there seems to be nothing like that. So does it mean the only way for doing this is: lock(a) { lock(b) { // this scope is in critical region } } Will this even work as expected? Although the code compiles, but I am not sure whether it would achieve what I am expecting it to. 回答1: I'd expect it to