reentrancy

Reentrancy and Reentrant in C?

眉间皱痕 提交于 2019-12-10 04:33:54
问题 I am reading a book called Linux System Programming . Quoting from this book: What about system calls and other library functions? What if your process is in the middle of writing to a file or allocating memory, and a signal handler writes to the same file or also invokes malloc()? Some functions are clearly not reentrant. If a program is in the middle of executing a nonreentrant function and a signal occurs and the signal handler then invokes that same nonreentrant function, chaos can ensue.

is this function reentrant?

风流意气都作罢 提交于 2019-12-09 03:15:31
void reverse_string(char* string, int str_size) { char tmp; int i = 0; int j = str_size - 1; while (i < j) { tmp = string[i]; string[i] = string[j]; string[j] = tmp; ++i; --j; } } I think this function is reentrant, since it doesn't use any global variable. It only modifies the arguments. My question is: is this function reentrant? if it is, is my argument good enough? thanks in advance Yes, this is a reentrant function. Reentrant functions are defined as those that can be called whilst they are themselves executing (either due to recursion, or concurrency). In this case, recursion is moot,

What strategy to use in Java for hierarchical reentrant read/write locking?

痴心易碎 提交于 2019-12-08 17:24:31
问题 I'm looking for en efficient system to have a series of read/write locks organized hierarchically to manage access to hierarchically organized resources. If a subtree is locked for write, then no other lock should be able to be obtained in the whole subtree until it is released; similarly, a write lock in a subtree should prevent locking in a parent. Here are the ideas I was contemplating: Use the Apache Commons Transaction . Unforunately, the project hasn't been updated since March 2008 and

thread-safe vs async-signal safe

馋奶兔 提交于 2019-12-08 02:55:35
问题 In APUP section 12.5 ,mentioned that: " If a function is reentrant with respect to multiple threads, we say that it is thread-safe. This doesn't tell us, however, whether the function is reentrant with respect to signal handlers." I was confusing why a function is thread-safe but maybe not async-signal safe. is there an example ? Thanks 回答1: A function can be made thread-safe by protecting the state it modifies with a mutex. This is, however, not async-signal-safe since if you call the

Qt documentation and reentrancy

筅森魡賤 提交于 2019-12-06 17:12:44
问题 The Qt documentation states this about thread-safety and reentrancy: Note: Qt classes are only documented as thread-safe if they are intended to be used by multiple threads. If a function is not marked as thread-safe or reentrant, it should not be used from different threads. If a class is not marked as thread-safe or reentrant then a specific instance of that class should not be accessed from different threads. This seems to state that every function and class in Qt should be considered non

Making bison/flex parser reentrant with integral YYSTYPE

自作多情 提交于 2019-12-06 12:18:58
问题 I'm having trouble following the steps to make my bison/flex parser reentrant with a minimum amount of fuss. The problem appears to be in the lexer. Since everything parser is re-entrant, I can no longer assign yylval directly. Instead, according to the Flex manual, I have to call this function: void yyset_lval ( YYSTYPE * yylvalp , yyscan_t scanner ); But the problem is, YYSTYPE is an integral type. It isn't a dynamically allocated value, and it isn't an lvalue at all, so I can't pass a

thread-safe vs async-signal safe

青春壹個敷衍的年華 提交于 2019-12-06 09:14:49
In APUP section 12.5 ,mentioned that: " If a function is reentrant with respect to multiple threads, we say that it is thread-safe. This doesn't tell us, however, whether the function is reentrant with respect to signal handlers." I was confusing why a function is thread-safe but maybe not async-signal safe. is there an example ? Thanks A function can be made thread-safe by protecting the state it modifies with a mutex. This is, however, not async-signal-safe since if you call the function e.g. from a signal handler the program can deadlock. A common function with this property is malloc(). 来源

Portable way to catch signals and report problem to the user

こ雲淡風輕ζ 提交于 2019-12-06 06:09:48
问题 If by some miracle a segfault occurs in our program, I want to catch the SIGSEGV and let the user (possibly a GUI client) know with a single return code that a serious problem has occurred. At the same time I would like to display information on the command line to show which signal was caught. Today our signal handler looks as follows: void catchSignal (int reason) { std :: cerr << "Caught a signal: " << reason << std::endl; exit (1); } I can hear the screams of horror with the above, as I

Call a non-reentrant native shared library from multiple Java threads

巧了我就是萌 提交于 2019-12-06 03:47:25
问题 I have some Java code that is calling some native code, originally written in Fortran, using JNA. (It's a numerical library, and lots of math people do their coding in Fortran.) It is compiled to a .so library, see below: Fortran: https://github.com/mizzao/libmao/tree/master/src/main/fortran Java binding: https://github.com/mizzao/libmao/blob/master/src/main/java/net/andrewmao/probability/MvnPackDirect.java I was getting great results with everything unit tested in my code, but then I tried

Gui reentrancy with managed waiting

偶尔善良 提交于 2019-12-05 19:42:41
I've found a reentrancy problem when using NotifyIcons. It's really easy to reproduce, just drop a NotiftIcon on a form and the click event should look like this: private bool reentrancyDetected; private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) { if (reentrancyDetected) MessageBox.Show("Reentrancy"); reentrancyDetected = true; lock (thisLock) { //do nothing } reentrancyDetected = false; } Also start a background thread which will cause some contention: private readonly object thisLock = new object(); private readonly Thread bgThread; public Form1() { InitializeComponent();