{
    "mode": "perldoc",
    "parameter": "Apache::Session::Lock::Semaphore",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Apache%3A%3ASession%3A%3ALock%3A%3ASemaphore/json",
    "generated": "2026-06-16T03:35:08Z",
    "synopsis": "use Apache::Session::Lock::Semaphore;\nmy $locker = Apache::Session::Lock::Semaphore->new;\ndie \"no semaphores\" unless $locker;\n$locker->acquirereadlock($ref);\n$locker->acquirewritelock($ref);\n$locker->releasereadlock($ref);\n$locker->releasewritelock($ref);\n$locker->releasealllocks($ref);",
    "sections": {
        "NAME": {
            "content": "Apache::Session::Lock::Semaphore - Provides mutual exclusion through semaphores\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Apache::Session::Lock::Semaphore;\n\nmy $locker = Apache::Session::Lock::Semaphore->new;\ndie \"no semaphores\" unless $locker;\n\n$locker->acquirereadlock($ref);\n$locker->acquirewritelock($ref);\n$locker->releasereadlock($ref);\n$locker->releasewritelock($ref);\n$locker->releasealllocks($ref);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Apache::Session::Lock::semaphore fulfills the locking interface of Apache::Session. Mutual\nexclusion is achieved through system semaphores and the IPC::Semaphore module.\n",
            "subsections": []
        },
        "CONFIGURATION": {
            "content": "The module must know how many semaphores to use, and what semaphore key to use. The number of\nsemaphores has an impact on performance. More semaphores means less lock contention. You should\nuse the maximum number of semaphores that your platform will allow. On stock NetBSD, OpenBSD,\nand Solaris systems, this is probably 16. On Linux 2.2, this is 32. This module tries to guess\nthe number based on your operating system, but it is safer to configure it yourself.\n\nTo set the number of semaphores, you need to pass an argument in the usual Apache::Session\nstyle. The name of the argument is NSems, and the value is an integer power of 2. For example:\n\ntie %s, 'Apache::Session::Blah', $id, {NSems => 16};\n\nYou may also need to configure the semaphore key that this package uses. By default, it uses key\n31818. You can change this using the argument SemaphoreKey:\n\ntie %s, 'Apache::Session::Blah', $id, {NSems => 16, SemaphoreKey => 42};\n",
            "subsections": []
        },
        "PROBLEMS": {
            "content": "There are a few problems that people frequently encounter when using this package.\n\nIf you get an invalid argument message, that usually means that the system is unhappy with the\nnumber of semaphores that you requested. Try decreasing the number of semaphores. The semaphore\nblocks that this package creates are persistent until the system is rebooted, so if you request\n8 semaphores one time and 16 semaphores the next, it won't work. Use the system commands ipcs\nand ipcrm to inspect and remove unwanted semphore blocks.\n",
            "subsections": [
                {
                    "name": "Cygwin",
                    "content": "IPC on Cygwin requires running cygserver. Without it, program will exit with \"Bad System call\"\nmessage. It cannot be intercepted with eval.\n\nRead /usr/share/doc/Cygwin/cygserver.README for more information.\n\nDarwin/MacOS X\nDarwin and MacOS X may not have semaphores, see\n<http://sysnet.ucsd.edu/~bellardo/darwin/sysvsem.html>\n\n*BSD\nError \"No space left on device\" means that maximum number of semaphores is reached. See\n<http://www.postgresql.org/docs/7.3/static/kernel-resources.html> for more information.\n"
                }
            ]
        },
        "AUTHOR": {
            "content": "This module was written by Jeffrey William Baker <jwbaker@acm.org>.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Apache::Session\n",
            "subsections": []
        }
    },
    "summary": "Apache::Session::Lock::Semaphore - Provides mutual exclusion through semaphores",
    "flags": [],
    "examples": [],
    "see_also": []
}