Looking for breakthrough ideas for innovation challenges? Try Patsnap Eureka!

Method for implementing spin lock in database

An implementation method and a technology of spin locks, which are applied in the database field, can solve problems such as locking deadlocks and spin locks that cannot adapt to application scenarios, and achieve the goals of avoiding deadlocks, improving the deadlock judgment process, and improving the locking process Effect

Inactive Publication Date: 2011-07-20
HUAZHONG UNIV OF SCI & TECH
View PDF2 Cites 15 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

It is precisely because of this principle that when there are multiple tasks competing for a certain spin lock, if the lock times out, multiple tasks will think that the lock has timed out at the same time, and each unlock the spin lock and try to lock it, resulting in multiple The task locks the same spin lock so that a deadlock occurs
Due to this problem, spin locks cannot adapt to more complex application scenarios

Method used

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Image

Smart Image Click on the blue labels to locate them in the text.
Viewing Examples
Smart Image
  • Method for implementing spin lock in database
  • Method for implementing spin lock in database
  • Method for implementing spin lock in database

Examples

Experimental program
Comparison scheme
Effect test

Embodiment Construction

[0030] Store two global variables in the shared memory, one is a spin lock variable, and the other is a variable used to generate an ID value, we call it an ID variable. All threads that want to use this spin lock need to access these two variables, and the two variables are initialized to 0 when the system is initialized.

[0031] The steps of locking a spin lock are as follows:

[0032] Step 101, the thread obtains the ID value from the ID variable. The ID value generation method is as follows: use the atomic operation to read the value in the ID variable and add 1 to its value. Since the read value operation and the add 1 operation are atomic, the same ID value will not be obtained when multiple threads access this ID variable within a similar time.

[0033] Step 102, the ID value obtained in step 101 and the state value after locking are synthesized into a spin lock variable value. When it is necessary to determine whether deadlock occurs during the locking process, foll...

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to View More

PUM

No PUM Login to View More

Abstract

The invention discloses a method for implementing a spin lock in a database. The method for implementing the spin lock in the database is characterized by comprising the following steps of: storing two global variables, namely a spin lock variable and an ID variable in a shared memory, and initializing the two variables as 0 when a system is initialized; and memorizing a current spin lock holdingthread by using a high storage value of spin lock variables, and implementing automatic unlocking of the spin lock according to the storage value when the lock holding thread is abnormal and exits tocause deadlock. By the method, possible deadlock when multiple tasks compete with the same spin lock is avoided, and the spin lock can protect the operation on a data structure for a long time and can process the deadlock problem caused by the abnormal end of a locking thread in the period by changing a locking flow and a deadlock judgment flow.

Description

technical field [0001] The invention relates to the technical field of databases, in particular to an improved implementation method for spin locks in the concurrency control process. Background technique [0002] In lock-based transaction concurrency control technology, databases often use spin locks to protect data structures and operations on them. The spin lock overhead is extremely small, but the spin lock can only protect light access to the data structure. During the spin lock protection period, there cannot be system calls or system interruptions. The protection time is very short, generally only for dozens of processors cycle. Because the principle of the spin lock is simple, the solution to the deadlock is also very simple. Usually, a timer with a fixed duration is used to time the task. Once the timing of the task is up, the subsequent task will be automatically unlocked directly. It is precisely because of this principle that when there are multiple tasks compe...

Claims

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to View More

Application Information

Patent Timeline
no application Login to View More
IPC IPC(8): G06F9/46
Inventor 王非黄本雄刘维邓磊
Owner HUAZHONG UNIV OF SCI & TECH
Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Patsnap Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Patsnap Eureka Blog
Learn More
PatSnap group products