Ticket lock

Ticket lock

A ticket lock is a form of lockless inter-thread synchronization.

Overview

Conventionally, inter-thread synchronization is achieved by using synchronization entities provided by the operating system, such as events, semaphores and mutexes.

For example, a thread will create a mutex and in the act of creation, "claim" the mutex. A mutex can have only one owner at any time. Other threads, when they come to the point where their behaviour must be synchronized, will attempt to "claim" the mutex; if they cannot, because another thread already owns the mutex, they automatically sleep until the thread which currently owns the mutex gives it up. Then one of the currently sleeping threads will automatically be awoken and given ownership of the mutex.

A ticket lock works as follows; there are two integer values which begin at 0. The first value is the queue ticket, the second is the dequeue ticket.

When a thread arrives, it atomically obtains and then increments the queue ticket. It then atomically compares its ticket with the dequeue ticket. If they are the same, the thread is permitted to enter the serialised code. If they are not the same, then another thread must already be in the serialised code and this thread must busy-wait or yield. When a thread has comes to leave the serialised code, it atomically increments the dequeue ticket, thus permitting the next waiting thread to enter the serialised code.

This approach is heavyweight (high-overhead, code intensive), in that such entities have a significant impact upon the performance of the operating system, since the operating system has to switch into a special mode when dealing with operations upon synchronization entities to ensure they provide synchronized behaviour.

A further drawback is that if the thread which owns the mutex fails, the entire application halts. (This type of problem applies to all synchronization entities).

Lockless locking

Lockless locking achieves inter-thread synchronization without the use of operating system provided sychronization entities.

Generally, two techniques are involved.

The first technique is the use of a special set of instructions which are guaranteed atomic by the CPU. This generally centers on an instrument known as Compare-and-swap. This instruction compares two variables and if they are the same, replaces one of the variable's values with a third value.

For example;

compare_and_swap ( destination, exchange, comparand );

Here the destination and comparand are compared. If they are identical, the value in exchange is placed in destination.

This first technique provides the vital inter-thread atomicity of operation. It would otherwise be impossible to perform any lockless locking, since on systems with multiple processors, even operations such as a simple assignment (let a = b) could be half-way through occurring while other operations occur on other processors; the software trying to sychronize across processors could never be sure that any operation had reached a sane state permitting it to be used in some way.

The second technique is to busy-wait or yield when it is clear that the current thread cannot be permitted to continue processing. This provides the vital ability to defer the processing done by a thread when such processing would violate the operations which are being serialised between threads.

External links


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Electronic ticket — E ticket redirects here. For the former Disneyland and Disney World tickets, see E ticket. An electronic ticket (commonly abbreviated as e ticket) is a digital ticket. It may be issued by an airline, in road, urban or rail public transport, and… …   Wikipedia

  • Sean Lock — Infobox Comedian name = Sean Lock imagesize = caption = pseudonym = birth name = birth date = birth date and age|1963|4|22|df=y birth place = Woking, Surrey, England death date = death place = medium = nationality = active = genre = subject =… …   Wikipedia

  • Open-jaw ticket — An open jaw ticket is an airline ticket in which a traveler returns to the airline from a city other than the one in which they arrived, or in which the final destination is not the same as the original departure city. The trip between these two… …   Wikipedia

  • George Mitchell (Chesterhall) Ltd v Finney Lock Seeds Ltd — George Mitchell (Chesterhall) Ltd v. Finney Lock Seeds Ltd [1983] QB 284 is a case on the sale of goods and exclusion clauses.Extracts from the judgmentAt 297, Lord Denning discusses the concept of freedom of contract. The heyday of freedom of… …   Wikipedia

  • The Big Lock-Out — Infobox Television episode | Title = The Big Lock Out Series = Black Books Season = 1 Episode = 5 Guests = Paul Beech, Steve Bodwitch, Nick Frost, Peter Serafinowicz, Tony Gray, Graham Linehan Dick Lunn. Airdate = October 27, 2000 Production =… …   Wikipedia

  • List of Mr. Bean episodes — This is an episode guide for the television series Mr. Bean, starring Rowan Atkinson, which ran between 1 January 1990 and 15 November 1995. Contents 1 Mr. Bean 2 The Return of Mr. Bean 3 The Curse of Mr. Bean …   Wikipedia

  • Seva in Tirumala — Main article: Tirumala Venkateswara Temple Arjitha Seva means performing seva to the Lord on payment of a fee to the temple. Tirumala Tirupati Devasthanams oversee the worship of the Lord and his finances. There are three kinds of Sevas: Daily… …   Wikipedia

  • performing arts — arts or skills that require public performance, as acting, singing, or dancing. [1945 50] * * * ▪ 2009 Introduction Music Classical.       The last vestiges of the Cold War seemed to thaw for a moment on Feb. 26, 2008, when the unfamiliar strains …   Universalium

  • Computer security incident management — In the fields of computer security and information technology, computer security incident management involves the monitoring and detection of security events on a computer or computer network, and the execution of proper responses to those events …   Wikipedia

  • Transportation Security Administration — Infobox Government agency agency name = Transportation Security Administration nativename = nativename a = nativename r = logo width = 200px logo caption = seal width = seal caption = formed = preceding1 = preceding2 = dissolved = superseding =… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”