A fan who has worked for 3 years went to an Internet company for an interview, but was scolded by the interviewer.
The interviewer said: "You don't know such a simple question? I can't talk anymore, go back and wait for the notice."
The question is: "What is a reentrant lock, and what does it do?"
For this question, let's take a look at the answers of ordinary people and experts.
Ordinary people:
Um. . . . . . . . . . . . . . . . . .
Expert:
OK
Reentrancy is an important concept in multithreaded concurrent programming.
Simply put, it is a function or code that is running, and the function or code is interrupted due to resource preemption or interruption.
After waiting for the execution of the interrupt program to end, re-enter the function or code to run, and the running result will not be affected, then the function or code is reentrant.
A reentrant lock, in simple terms, means that if a thread preempts a mutex lock resource and competes for the same lock before the lock is released, it does not need to wait, but only needs to record the number of reentrants.
In multi-threaded concurrent programming, most locks are reentrant, such as Synchronized, ReentrantLock, etc., but there are also locks that do not support reentrancy, such as the read-write lock StampedLock provided in JDK8.
The main problem of lock reentrancy is to avoid the problem of thread deadlock.
Because a thread that has acquired synchronization lock X, when it competes for lock X before releasing lock X, it is equivalent to waiting for it to release the lock, which is obviously impossible.
The above is my understanding of the problem.
Summarize
Regarding this question, it is actually to examine the basic knowledge of job seekers.
The Internet giants will have a particularly deep inspection of the basics. If necessary, they still need to spend more time on research outside of work.
Moreover, for 3 years of work experience, it is not too much to investigate such issues.
If you have any interview questions, career development questions, or study questions, you can PM me.
Copyright notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated. Please indicate the source forMic带你学架构
!
If this article is helpful to you, please help to follow and like, your persistence is the driving force for my continuous creation. Welcome to follow the WeChat public account of the same name to get more technical dry goods!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。