Przewracamy stronę.
Następny rozdział już się zbliża…
Psst… czytaj po swojemu.
Kroje i motywy znajdziesz w Wygląd. Twoje oczy też mają głos.
Następny rozdział już się zbliża…
A contract flaw where an external call re-enters before state updates, used in classic DeFi hacks.
Sprawdzanie obsługi czytania na głos…
Ta lektura jest obecnie dostępna po angielsku. Interfejs używa wybranego języka.
Przeczytaj angielski oryginał →In programming, reentrancy is the property of a function or subroutine which can be interrupted and then resumed before it finishes executing. This means that the function can be called again before it completes its previous execution. Reentrant code is designed to be safe and predictable when multiple instances of the same function are called simultaneously or in quick succession.
A computer program or subroutine is called reentrant if multiple invocations can safely run concurrently on multiple processors, or if on a single-processor system its execution can be interrupted and a new execution of it can be safely started (it can be "re-entered"). The interruption could be caused by an internal action such as a jump or call (which might be a recursive call; reentering a function is a generalization of recursion), or by an external action such as an interrupt or signal.
This definition originates from multiprogramming environments, where multiple processes may be active concurrently and where the flow of control could be interrupted by an interrupt and transferred to an interrupt service routine (ISR) or "handler" subroutine. Any subroutine used by the handler that could potentially have been executing when the interrupt was triggered should be reentrant. Similarly, code shared by two processors accessing shared data should be reentrant. Often, subroutines accessible via the operating system kernel are not reentrant.
Hence, interrupt service routines are limited in the actions they can perform; for instance, they are usually restricted from accessing the file system and sometimes even from allocating memory.
Other terms used for reentrant programs include "sharable code". Reentrant subroutines are sometimes marked in reference material as being "signal safe". Reentrant programs are often "pure procedures".
Generally speaking, a function produces output data based on some input data (though both are optional, in general). Shared data could be accessed by any function at any time. If data can be changed by any function (and none keep track of those changes), there is no guarantee to those that share a datum that that datum is the same as at any time before.
Data has a characteristic called scope, which describes where in a program the data may be used. Data scope is either global (outside the scope of any function and with an indefinite extent) or local (created each time a function is called and destroyed upon exit).
Local data is not shared by any routines, re-entering or not; therefore, it does not affect re-entrance. Global data is defined outside functions and can be accessed by more than one function, either in the form of global variables (data shared between all functions), or as static variables (data shared by all invocations of the same function). In object-oriented programming, global data is defined in the scope of a class and can be private, making it accessible only to functions of that class.
There is also the concept of instance variables, where a class variable is bound to a class instance. For these reasons, in object-oriented programming, this distinction is usually reserved for the data accessible outside of the class (public), and for the data independent of class instances (static).
Wybrano i przeformatowano z Reentrancy (computing), przez współautorów, na licencji CC BY-SA 4.0. Wersja 1377746638. Sekcje i formatowanie skrócono; podlinkowana wersja zawiera pełny kontekst i historię wkładów. Tekst referencyjny zachowuje tę samą licencję. Dodatkowe odnośniki do cytowań pochodzą z tej wersji i nie zostały tu niezależnie sprawdzone.