Questions tagged [critical-section]

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.

529 questions
-3
votes
2 answers

A critical section inside or outside a thread class is better? [Example inside]

I have several threads (Providers), that are used by other threads (Workers) on concurrent basis. Several threads means severan critical sections according to threads. Is it impossble to place a critical section variable inside a thread class, or…
notricky
  • 179
  • 1
  • 2
  • 18
-3
votes
1 answer

c# Lock Doesn`t work / Critical Section

I`m trying to advance a static (int) counter using two different threads in a FOR loop, so if the loop is runs 10 times I (should) get counter=20. for some reason i keep getting different values each time i run the loop (19,20,21), even though i…
Ran
  • 63
  • 7
-4
votes
1 answer

Don't agree with Peterson's solution

#define FALSE 0 #define TRUE 1 #define N 2 int turn; int interested[N]; void enter_region(int process) { int other; other = 1 - process; interested[process] == TRUE; turn = process; // set flag while (turn == process && interested[other]…
-5
votes
1 answer

how to write an atomic account transfer function

So suppose I get two bank account A and B, and I need to atomically transfer money. The set up is the following: ` struct account{ int64 amount; pthread_mutex_lock m; } ` here is my approach: ` bool Transfer(int from_account, int…
1 2 3
35
36