Many systems impose restrictions on the size of the thread-local memory block, in fact often rather tight limits. Threads then only have to synchronise a final accumulation from their own thread-local variable into a single, truly global variable. Alternatively, each thread might accumulate into a thread-local variable (that, by definition, cannot be read from or written to from other threads, implying that there can be no race conditions). To avoid a race condition, every access to this global variable would have to be protected by a mutex. A second use case would be multiple threads accumulating information into a global variable. The solution is to have errno be a variable that looks like it is global, but in fact exists once per thread-i.e., it lives in thread-local storage. If errno were a global variable, a call of a system function on one thread may overwrite the value previously set by a call of a system function on a different thread, possibly before following code on that different thread could check for the error condition. An example of such situations is where functions use a global variable to set an error condition (for example the global variable errno used by many functions of the C library). While the use of global variables is generally discouraged in modern programming, legacy operating systems such as UNIX are designed for uniprocessor hardware and require some additional mechanism to retain the semantics of pre- reentrant APIs. Thread-local storage ( TLS) is a computer programming method that uses static or global memory local to a thread.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |