reentrancy

Recommended practices for re-entrant code in C, C++

血红的双手。 提交于 2019-12-03 04:08:35
I was going through a re-entrancy guide on recommended practices when writing re-entrant code. What other references and resources cover this topic? What lint-like tools can be used to check for these issues? The guide is sufficient. My personal rule of thumbs are only 2 for re-reentering code: take only pass by value parameters, used only value passed in as parameters in the function. if I need to use any global parameters or pointer (for performance or storage sake), use a mutex or semaphore to control access to it. Do use local variables. Don't use static locals or global variables, even

Does SemaphoreSlim (.NET) prevent same thread from entering block?

你说的曾经没有我的故事 提交于 2019-12-03 03:12:20
I have read the docs for SemaphoreSlim SemaphoreSlim MSDN which indicates that the SemaphoreSlim will limit a section of code to be run by only 1 thread at a time if you configure it as: SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(1, 1); However, it doesn't indicate if it stops the same thread from accessing that code. This comes up with async and await. If one uses await in a method, control leaves that method and returns when whatever task or thread has completed. In my example, I use a button with an async button handler. It calls another method (Function1) with 'await'. Function1 in

Mixing synchronized() with ReentrantLock.lock()

北战南征 提交于 2019-12-03 03:01:00
In Java, do ReentrantLock.lock() and ReetrantLock.unlock() use the same locking mechanism as synchronized() ? My guess is "No," but I'm hoping to be wrong. Example: Imagine that Thread 1 and Thread 2 both have access to: ReentrantLock lock = new ReentrantLock(); Thread 1 runs: synchronized (lock) { // blah } Thread 2 runs: lock.lock(); try { // blah } finally { lock.unlock(); } Assume Thread 1 reaches its part first, then Thread 2 before Thread 1 is finished: will Thread 2 wait for Thread 1 to leave the synchronized() block, or will it go ahead and run? No, Thread 2 can lock() even when Thread

Is the volatile keyword required for fields accessed via a ReentrantLock?

烂漫一生 提交于 2019-12-03 01:11:12
My question refers to whether or not the use of a ReentrantLock guarantees visibility of a field in the same respect that the synchronized keyword provides. For example, in the following class A , the field sharedData does not need to be declared volatile as the synchronized keyword is used. class A { private double sharedData; public synchronized void method() { double temp = sharedData; temp *= 2.5; sharedData = temp + 1; } } For next example using a ReentrantLock however, is the volatile keyword on the field necessary? class B { private final ReentrantLock lock = new ReentrantLock();

What is a re-entrant parser?

梦想与她 提交于 2019-12-02 23:40:26
Can someone explain this to me? In particular the difference between: http://github.com/whymirror/greg and http://piumarta.com/software/peg/ The former being a re-entrant version of the later. At its simplest a re-entrant parser doesn't use global variables and thus can have multiple instances active at the same time (not necessarily related to threading, but this is the main use case I suspect). In more complex use cases, however, you can have a parser that parses, in effect, multiple languages in the same source document. Consider a JSP parser, for example, that has to parse Java code and

Writing re-entrant lexer with Flex

為{幸葍}努か 提交于 2019-12-01 05:11:46
I'm newbie to flex. I'm trying to write a simple re-entrant lexer/scanner with flex. The lexer definition goes below. I get stuck with compilation errors as shown below (yyg issue): reentrant.l: /* Definitions */ digit [0-9] letter [a-zA-Z] alphanum [a-zA-Z0-9] identifier [a-zA-Z_][a-zA-Z0-9_]+ integer [0-9]+ natural [0-9]*[1-9][0-9]* decimal ([0-9]+\.|\.[0-9]+|[0-9]+\.[0-9]+) %{ #include <stdio.h> #define ECHO fwrite(yytext, yyleng, 1, yyout) int totalNums = 0; %} %option reentrant %option prefix="simpleit_" %% ^(.*)\r?\n printf("%d\t%s", yylineno++, yytext); %% /* Routines */ int yywrap

What is the difference between Lock and RLock

戏子无情 提交于 2019-11-29 20:25:59
From the docs : threading.RLock() -- A factory function that returns a new reentrant lock object. A reentrant lock must be released by the thread that acquired it. Once a thread has acquired a reentrant lock, the same thread may acquire it again without blocking; the thread must release it once for each time it has acquired it. I am not sure why do we need this? what's the difference between Rlock and Lock ? The main difference is that a Lock can only be acquired once. It cannot be acquired again, until it is released. (After it's been released, it can be re-acaquired by any thread). An RLock

what is the difference between re-entrant function and recursive function in C?

依然范特西╮ 提交于 2019-11-28 17:17:10
In C I know about the recursive function but I heard about the re-entrant function. What is that? And whats the difference between them? A function is re-entrant if it supports having multiple threads of execution "going through" it at the same time. This might be due to actual multi-threading, and I use this case below, or due to other things as pointed out by other posters. Multi-threading was the first that came to mind, and is perhaps also the easiest to understand, so I focused on that case. This means that the function cannot use static "global" data, since that data would then be

'Reentrancy' in java

会有一股神秘感。 提交于 2019-11-28 16:12:28
Reentrancy means that locks are acquired on a per-thread rather than per-invocation basis. Since an intrinsic lock is held by a thread, doesn't it mean that a thread run once equals an invocation basis? Thank you, it seems mean that: in a thread,if I get a lock lockA when process function doA which call function doB , and doB also need a lock lockA ,then there wil be a reentrancy. In Java, this phenomenon is acquired per thread, so I needn't consider deadlocks? Reentrancy means that locks are acquired on a per-thread rather than per-invocation basis. That is a misleading definition. It is true

Does the application GetMessage even during MessageBox?

冷暖自知 提交于 2019-11-27 08:49:14
问题 While handling WM_TIMER, I called MessageBox . As a result, a message box popped up with the frequency of the timer. So I believe that the application was trying to continue to process queued/non-queued messages even during MessageBox . Am I right? I know that according to MSDN, while an application is sending a message to a different thread from the sending thread, the sending thread will try to process non-queued messages it receives before SendMessage returns --- i.e. before the target