⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme

📁 这是linux下运行的mysql软件包,可用于linux 下安装 php + mysql + apach 的网络配置
💻
字号:
# $Id: README,v 11.2 1999/11/21 18:12:48 bostic Exp $Note: this only applies to locking using test-and-set and fcntl calls,pthreads were added after this was written.Resource locking routines: lock based on a db_mutex_t.  All this gunk(including trying to make assembly code portable), is necessary becauseSystem V semaphores require system calls for uncontested locks and wedon't want to make two system calls per resource lock.First, this is how it works.  The db_mutex_t structure contains a resourcetest-and-set lock (tsl), a file offset, a pid for debugging and statisticsinformation.If HAVE_MUTEX_THREADS is defined (i.e. we know how to do test-and-setsfor this compiler/architecture combination), we try and lock the resourcetsl __os_spin() times.  If we can't acquire the lock that way, we use asystem call to sleep for 1ms, 2ms, 4ms, etc.  (The time is bounded at 1second, just in case.)  Using the timer backoff means that there are twoassumptions: that locks are held for brief periods (never over systemcalls or I/O) and that locks are not hotly contested.If HAVE_MUTEX_THREADS is not defined, i.e. we can't do test-and-sets, weuse a file descriptor to do byte locking on a file at a specified offset.In this case, ALL of the locking is done in the kernel.  Because filedescriptors are allocated per process, we have to provide the filedescriptor as part of the lock call.  We still have to do timer backoffbecause we need to be able to block ourselves, i.e. the lock managercauses processes to wait by having the process acquire a mutex and thenattempting to re-acquire the mutex.  There's no way to use kernel lockingto block yourself, i.e. if you hold a lock and attempt to re-acquire it,the attempt will succeed.Next, let's talk about why it doesn't work the way a reasonable personwould think it should work.Ideally, we'd have the ability to try to lock the resource tsl, and ifthat fails, increment a counter of waiting processes, then block in thekernel until the tsl is released.  The process holding the resource tslwould see the wait counter when it went to release the resource tsl, andwould wake any waiting processes up after releasing the lock.  This wouldactually require both another tsl (call it the mutex tsl) andsynchronization between the call that blocks in the kernel and the actualresource tsl.  The mutex tsl would be used to protect accesses to thedb_mutex_t itself.  Locking the mutex tsl would be done by a busy loop,which is safe because processes would never block holding that tsl (allthey would do is try to obtain the resource tsl and set/check the waitcount).  The problem in this model is that the blocking call into thekernel requires a blocking semaphore, i.e. one whose normal state islocked.The only portable forms of locking under UNIX are fcntl(2) on a filedescriptor/offset, and System V semaphores.  Neither of these lockingmethods are sufficient to solve the problem.The problem with fcntl locking is that only the process that obtained thelock can release it.  Remember, we want the normal state of the kernelsemaphore to be locked.  So, if the creator of the db_mutex_t were toinitialize the lock to "locked", then a second process locks the resourcetsl, and then a third process needs to block, waiting for the resourcetsl, when the second process wants to wake up the third process, it can'tbecause it's not the holder of the lock!  For the second process to bethe holder of the lock, we would have to make a system call peruncontested lock, which is what we were trying to get away from in thefirst place.There are some hybrid schemes, such as signaling the holder of the lock,or using a different blocking offset depending on which process isholding the lock, but it gets complicated fairly quickly.  I'm open tosuggestions, but I'm not holding my breath.Regardless, we use this form of locking when HAVE_SPINLOCKS is notdefined, (i.e. we're locking in the kernel) because it doesn't have thelimitations found in System V semaphores, and because the normal state ofthe kernel object in that case is unlocked, so the process releasing thelock is also the holder of the lock.The System V semaphore design has a number of other limitations that makeit inappropriate for this task.  Namely:First, the semaphore key name space is separate from the file system namespace (although there exist methods for using file names to createsemaphore keys).  If we use a well-known key, there's no reason to believethat any particular key will not already be in use, either by anotherinstance of the DB application or some other application, in which casethe DB application will fail.  If we create a key, then we have to use afile system name to rendezvous and pass around the key.Second, System V semaphores traditionally have compile-time, system-widelimits on the number of semaphore keys that you can have.  Typically, thatnumber is far too low for any practical purpose.  Since the semaphorespermit more than a single slot per semaphore key, we could try and getaround that limit by using multiple slots, but that means that the filethat we're using for rendezvous is going to have to contain slotinformation as well as semaphore key information, and we're going to bereading/writing it on every db_mutex_t init or destroy operation.  Anyhow,similar compile-time, system-wide limits on the numbers of slots persemaphore key kick in, and you're right back where you started.My fantasy is that once POSIX.1 standard mutexes are in wide-spread use,we can switch to them.  My guess is that it won't happen, because thePOSIX semaphores are only required to work for threads within a process,and not independent processes.Note: there are races in the statistics code, but since it's just that,I didn't bother fixing them.  (The fix requires a mutex tsl, so, when/ifthis code is fixed to do rational locking (see above), then change thestatistics update code to acquire/release the mutex tsl.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -