critical-section

Delphi multi-threading file write: I/O error 32

不打扰是莪最后的温柔 提交于 2021-02-18 17:49:14
问题 I created a class for writing thread-safe log in a text file using CriticalSection . I am not an expert of CriticalSection and multi-threading programming (...and Delphi), I'm definitely doing something wrong... unit ErrorLog; interface uses Winapi.Windows, System.SysUtils; type TErrorLog = class private FTextFile : TextFile; FLock : TRTLCriticalSection; public constructor Create(const aLogFilename:string); destructor Destroy; override; procedure Write(const ErrorText: string); end;

Windows critical sections fairness

谁说我不能喝 提交于 2021-02-08 11:58:42
问题 I've a question about the fairness of the critical sections on Windows, using EnterCriticalSection and LeaveCriticalSection methods. The MSDN documentation specifies: "There is no guarantee about the order in which threads will obtain ownership of the critical section, however, the system will be fair to all threads." The problem comes with an application I wrote, which blocks some threads that never enter critical section, even after a long time; so I perfomed some tests with a simple c

Windows critical sections fairness

允我心安 提交于 2021-02-08 11:58:19
问题 I've a question about the fairness of the critical sections on Windows, using EnterCriticalSection and LeaveCriticalSection methods. The MSDN documentation specifies: "There is no guarantee about the order in which threads will obtain ownership of the critical section, however, the system will be fair to all threads." The problem comes with an application I wrote, which blocks some threads that never enter critical section, even after a long time; so I perfomed some tests with a simple c

is a Python dictionary thread-safe when keys are thread IDs?

断了今生、忘了曾经 提交于 2021-01-28 00:22:20
问题 Is a Python dictionary thread safe when using the thread ID of the current thread only to read or write? Like import thread import threading class Thread(threading.Thread): def __init__(self, data): super(Thread, self).__init__() self.data = data def run(self): data = self.data[thread.get_ident()] # ... 回答1: If data is a standard Python dictionary, the __getitem__ call is implemented entirely in C, as is the __hash__ method on the integer value returned by thread.get_ident() . At that point

PHP/MySQL Critical section

六月ゝ 毕业季﹏ 提交于 2020-12-31 04:52:39
问题 I'm using PHP with PDO and InnoDB tables. I only want the code to allow one user-submitted operation to complete, the user can either cancel or complete. But in the case that the user posts both operations, I want one of the requests to fail and rollback, which isn't happening right now, both are completing without exception/error . I thought deleting the row after checking it exists would be enough. $pdo = new PDO(); try { $pdo->beginTransaction(); $rowCheck = $pdo->query("SELECT * FROM

PHP/MySQL Critical section

℡╲_俬逩灬. 提交于 2020-12-31 04:52:35
问题 I'm using PHP with PDO and InnoDB tables. I only want the code to allow one user-submitted operation to complete, the user can either cancel or complete. But in the case that the user posts both operations, I want one of the requests to fail and rollback, which isn't happening right now, both are completing without exception/error . I thought deleting the row after checking it exists would be enough. $pdo = new PDO(); try { $pdo->beginTransaction(); $rowCheck = $pdo->query("SELECT * FROM

PHP/MySQL Critical section

北战南征 提交于 2020-12-31 04:52:25
问题 I'm using PHP with PDO and InnoDB tables. I only want the code to allow one user-submitted operation to complete, the user can either cancel or complete. But in the case that the user posts both operations, I want one of the requests to fail and rollback, which isn't happening right now, both are completing without exception/error . I thought deleting the row after checking it exists would be enough. $pdo = new PDO(); try { $pdo->beginTransaction(); $rowCheck = $pdo->query("SELECT * FROM

Why did CRITICAL_SECTION performance become worse on Win8

ⅰ亾dé卋堺 提交于 2020-12-30 09:47:37
问题 It seems like CRITICAL_SECTION performance became worse on Windows 8 and higher. (see graphs below) The test is pretty simple: some concurrent threads do 3 million locks each to access a variable exclusively. You can find the C++ program at the bottom of the question. I run the test on Windows Vista, Windows 7, Windows 8, Windows 10 (x64, VMWare, Intel Core i7-2600 3.40GHz). The results are on the image below. The X-axis is the number of concurrent threads. The Y-axis is the elapsed time in

Why is notify required inside a critical section?

时光毁灭记忆、已成空白 提交于 2020-02-25 04:10:44
问题 I'm reading this book here (official link, it's free) to understand threads and parallel programming. Here's the question. Why does the book say that pthread_cond_signal must be done with a lock held to prevent data race? I wasn't sure, so I referred to this question (and this question too), which basically said "no, it's not required". Why would a race condition occur? What and where is the race condition being described? The code and passage in question is as follows. ... The code to wake a

Why is notify required inside a critical section?

假如想象 提交于 2020-02-25 04:10:31
问题 I'm reading this book here (official link, it's free) to understand threads and parallel programming. Here's the question. Why does the book say that pthread_cond_signal must be done with a lock held to prevent data race? I wasn't sure, so I referred to this question (and this question too), which basically said "no, it's not required". Why would a race condition occur? What and where is the race condition being described? The code and passage in question is as follows. ... The code to wake a