Is SetEvent atomic?
Is it safe to have 2 or more threads call the Win32 API's SetEvent on the same event handler not being protected by a critical section? ...
Is it safe to have 2 or more threads call the Win32 API's SetEvent on the same event handler not being protected by a critical section? ...
// A Mutex allows threads mutually exclusive access to a resource. //----------------------------------------------------------------------- class Mutex { private: CRITICAL_SECTION m_mutex; public: Mutex() { InitializeCriticalSection(&m_mutex); } ~Mutex() { DeleteCriticalSection(&m_mutex); } void acquire() { Enter...
I need to work with array from several threads, so I use CRITICAL SECTION to give it an exclusive access to the data. Here is my template: #include "stdafx.h" #ifndef SHAREDVECTOR_H #define SHAREDVECTOR_H #include <vector> #include <windows.h> template<class T> class SharedVector { std::vector<T> vect; CRITICAL_SECTION cs; ...
I`m writing a chat using WinSock2 and WinAPI functions. And I have a little trouble. I store the std::vector of client connections on server. When new client connects, new thread starts and all work with the client is done in this new thread. I do not use classes (I know it is not very good) so this list of connections is just defined as...
Exact Duplicate Initialize Critical Section only once for a process I have a dll that creates a global critical section, initializes and use it. Now a third party application is using / loading the dll more than once which leads to a heap corruption. The appverifier warns me with a --> VERIFIER STOP 00000211: pid 0x1470: Critic...
We have a D2007 application whose memory footprint grows steadily when running on Windows Server 2008 (x64, sp1). It behaves normally on Windows Server 2003 (x32 or x64), XP, etc... where it goes up and down as expected. We have tried with the included Memory Manager or the latest FastMM4 4.92 with the same results. Has anyone tried t...
It seems that using Critical Sections quite a bit in Vista/Windows Server 2008 leads to the OS not fully regaining the memory. We found this problem with a Delphi application and it is clearly because of using the CS API. (see this SO question) Has anyone else seen it with applications developed with other languages (C++, ...)? The s...
I was debugging a multi-threaded application and found the internal structure of CRITICAL_SECTION. I found data member LockSemaphore of CRITICAL_SECTION an interesting one. It looks like LockSemaphore is an auto-reset event (not a semaphore as the name suggests) and operating system creates this event silently when first time a thread ...
So App Verifier is throwing this exception. From what I gather, the text of this message is a little misleading. The problem appears to be that the the critical section was created by a thread that is being destroyed before the critical section is destroyed. It's a relatively simple fix but does anyone know what the ramifications ar...
I have to implement a read/write lock in C++ using the Win32 api as part of a project at work. All of the existing solutions use kernel objects (semaphores and mutexes) that require a context switch during execution. This is far too slow for my application. I would like implement one using only critical sections, if possible. The loc...
To our great surprise we found recently this. With SP1 for Windows 2003 Microsoft changed a way critical sections behave. Earlier threads wanting to access them were served in FIFO manner. Right now they are served in pure "random" way. In our case we had something like this: // I now it's kind of ugly design but works void Class:RunIn...
i was asked to write: enter function and exit function for the following case: there are N processes and M types of processes (N>>M) tere is a critical section in which all processes with the same type can enter. for example: if type A is in cs, type B cannot enter cs. but all processes with type A can enter. i can use only mutex and "...
What is the relation ship between CRITICAL_SECTION and CCriticalSection. is CCriticalSection a wrapper of CRITICAL_SECTION? BTW: I think the following code is meanless because the cs is not Global, it initial every times before lock() so it can't lock the XXX , is it ? int func { CCriticalSection cs; cs.Lock(); XXX cs.Unlock(); } Ma...
I am attempting a multiple producer/consumer problem in C, but its not working as expected. The following is some pseudo code to represent my implementation. Thread thread1; Thread thread2; Thread thread3; Data data1; Mutex data1_mutex; Semaphore data1_empty; Semaphore data1_fill; Data data2; Mutex data2_mutex; Semaphore data2_empty; ...
Hello! 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)? Sorry for my English! Thanks for your help! ...
The Operating System Concepts 6th edition present one trival algorithm to implementate ciritical section. do{ while (turn != i); critical section trun = j; remainder section } while(1); Note,Pi is the process with identifier i,Pj is the process with identifier j.To simlify the question,the book limit the i,j to 0 and 1,th...
I have the following piece of code in thread A, which blocks using pthread_cond_wait() pthread_mutex_lock(&my_lock); if ( false == testCondition ) pthread_cond_wait(&my_wait,&my_lock); pthread_mutex_unlock(&my_lock); I have the following piece of code in thread B, which signals thread A pthread_mutex_lock(&my_lock...
hey, i'm not sure about something. when i use critical_section/mutex/semaphor in c++ for example , how does the busy_wait problem being prevented ? what i mean is when a thread reaches a critical section and the critical section is occupied by other thread, what prevents the thread from wasting cycle time and wait for nothing ? for e...
I'm trying to implement a critical section in CUDA using atomic instructions, but I ran into some trouble. I have created the test program to show the problem: #include <cuda_runtime.h> #include <cutil_inline.h> #include <stdio.h> __global__ void k_testLocking(unsigned int* locks, int n) { int id = threadIdx.x % n; while (atomi...
I am writing a program where there is an object shared by multiple threads: a. multiple write threads write to the object (all running the same function) b. a read thread which accesses the object every 5 seconds c. a read thread which accesses the object there is a user request It is obviously necessary to lock the object when writing ...