Critical section refers to either a piece of code that will run concurrently in several threads accessing global data or resources (requiring synchronisation), or a user-level spinlock combined with a mutex object under the Windows operating system. A critical section in the latter sense is functionally identical to a mutex that it cannot shared with a different process and that it is several orders of magnitudes faster in the non-congested case.
Questions tagged [critical-section]
529 questions
-1
votes
1 answer
Parallelize decoding function with OpenMP
I am trying to parallelize the following decoding function (from binary code to int):
int decodePrimeFactorization(int code){
int prod = 1;
#pragma omp parallel for
for (int j=0; j

AbdelKh
- 499
- 7
- 19
-1
votes
1 answer
How do multiple threads don't deadlock in critical section using Semaphores
I've recently read up about Semaphores and get most of the logic.
Except for the fact that,
When let's say the value of Semaphore is 5, that means 5 threads can't enter the critical section, but how do we make sure these 5 threads don't try to…

roro
- 193
- 3
- 16
-1
votes
1 answer
Is there any performance impact on declaring a variable inside critical section block compared to when declared outside?
Suppose there is a code as shown below
void func1() // first way
{
CRITICALSECTIONTYPE CS;
ENTERCRITICALSECTION(CS);
int x = getValue();
LEAVECRITICALSECTION(CS);
}
void func2() // second way
{
int x;
…

Abhinav
- 1,496
- 3
- 15
- 31
-1
votes
1 answer
From where is the code for dealing with critical section originated?
While learning the subject of operating systems, Critical Section is a topic which I've come across. To solve this problem, certain methods are provided like semaphores, certain software solutions, etc...etc..etc. But I've a question that from where…

Arlene Batada
- 1,565
- 2
- 11
- 11
-1
votes
1 answer
Pthread c++ and mutex
a question about pthread and mutex.
I have architecture producer consumer with a shared queue.
I have two queue operations: push and pop.
for both of these operation I use a mutex (lock - implementation - unlock).
I did not understand a…

Safari
- 11,437
- 24
- 91
- 191
-1
votes
1 answer
How do I detect critical sections in a C program by analyzing it programmatically?
I want to create a tool which analyzes a C program for critical sections during the compilation phase. I am looking for the right algorithm which would let me do this. It can be at any phase of the compiler.

decached
- 915
- 1
- 10
- 24
-1
votes
1 answer
Is it the good marker or not Ada95?
Consider the following controller (protected object) in Ada95 to adapt that a Task calls Waiting() this one its not going to be put on waiting if the waiting marker (Marker) corresponds already on the marker of selection (Selecting_Marker) only…

Dardan
- 43
- 4
-2
votes
1 answer
Delphi: Multithreading, Thread safe not working
When data is sending to "tunnel" socket, it's sometimes merged, implemented the Critical Section but it's not working..
What I'm doing wrong ?
type
my_ff_thread = class;
my_ss_thread = class;
Tmy_tunnel_from_MappedPortTCP = class;
…

jmp
- 2,456
- 3
- 30
- 47
-2
votes
1 answer
How can I resolve a critical section runtime error with PHP sessions in WordPress?
A PHP session was created by a session_start() function call. This interferes with REST API and loopback requests. The session should be closed by session_write_close() before making any HTTP requests.please help how to resolve this problem I m…
-2
votes
1 answer
Why does having the same delay in the same streams affect the result?
I have 2 unsynchronized threads that modify the global variable. Each thread has 12 iterations. Before the modification command, each stream has a 1 ms delay. As a result, the global variable is equal to 112, which is logical, since the streams…

volvo
- 9
- 2
-2
votes
1 answer
Avoiding race condition in OpenMP?
I was reading about OpenMP and shared memory programming and fell over this pseudo code that has an integer x and two threads
thread 1
x++;
thread 2
x--;
This will lead to a race condition, but can be avoided. I want to avoid it using OpenMP, how…

George W
- 51
- 1
- 7
-2
votes
1 answer
Java Threads producer-consumer shared buffer
Implement producer consumer problem using threads in Java. Producers and consumers share a buffer, producers put elements in buffer and consumers consume elements from the shared buffer. If the buffer is full producers should wait till consumers…

Alireza M. Kamelabad
- 53
- 9
-2
votes
2 answers
Read/Write lock using only critical section causes deadlock
After going through this question with the same title and its answers, I thought to try something that should really work only using critical section and thus should be much faster that existing solutions (which use other kernel objects too like…

Atul
- 3,778
- 5
- 47
- 87
-2
votes
3 answers
Thread synchronization design
I have a class in my project which contains 4 vectors
m_vecA;
m_vecB;
m_vecC;
m_vecD;
These vectors can be accessed in different threads.I can use one critical section and protect all these vectors with it.
Or is it good idea to have 4 critical…

anand
- 11,071
- 28
- 101
- 159
-3
votes
1 answer
replacement for #pragma omp critical (C++)
I am using openMp on a nested loop which works like this
#pragma omp parallel shared(vector1) private(i,j)
{
#pragma omp for schedule(dynamic)
for (i = 0; i < vector1.size(); ++i){
//some code here
for (j = 0; j <…

j.doe
- 13
- 6