{
    "content": [
        {
            "type": "text",
            "text": "# Thread::Semaphore (perldoc)\n\n## NAME\n\nThread::Semaphore - Thread-safe semaphores\n\n## SYNOPSIS\n\nuse Thread::Semaphore;\nmy $s = Thread::Semaphore->new();\n$s->down();   # Also known as the semaphore P operation.\n# The guarded section is here\n$s->up();     # Also known as the semaphore V operation.\n# Decrement the semaphore only if it would immediately succeed.\nif ($s->downnb()) {\n# The guarded section is here\n$s->up();\n}\n# Forcefully decrement the semaphore even if its count goes below 0.\n$s->downforce();\n# The default value for semaphore operations is 1\nmy $s = Thread::Semaphore->new($initialvalue);\n$s->down($downvalue);\n$s->up($upvalue);\nif ($s->downnb($downvalue)) {\n...\n$s->up($upvalue);\n}\n$s->downforce($downvalue);\n\n## DESCRIPTION\n\nSemaphores provide a mechanism to regulate access to resources. Unlike locks, semaphores aren't\ntied to particular scalars, and so may be used to control access to anything you care to use\nthem for.\n\n## Sections\n\n- **NAME**\n- **VERSION**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **METHODS**\n- **NOTES**\n- **SEE ALSO**\n- **MAINTAINER**\n- **LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Thread::Semaphore",
        "section": "",
        "mode": "perldoc",
        "summary": "Thread::Semaphore - Thread-safe semaphores",
        "synopsis": "use Thread::Semaphore;\nmy $s = Thread::Semaphore->new();\n$s->down();   # Also known as the semaphore P operation.\n# The guarded section is here\n$s->up();     # Also known as the semaphore V operation.\n# Decrement the semaphore only if it would immediately succeed.\nif ($s->downnb()) {\n# The guarded section is here\n$s->up();\n}\n# Forcefully decrement the semaphore even if its count goes below 0.\n$s->downforce();\n# The default value for semaphore operations is 1\nmy $s = Thread::Semaphore->new($initialvalue);\n$s->down($downvalue);\n$s->up($upvalue);\nif ($s->downnb($downvalue)) {\n...\n$s->up($upvalue);\n}\n$s->downforce($downvalue);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 25,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 61,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "MAINTAINER",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "LICENSE",
                "lines": 3,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Thread::Semaphore - Thread-safe semaphores\n",
                "subsections": []
            },
            "VERSION": {
                "content": "This document describes Thread::Semaphore version 2.13\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Thread::Semaphore;\nmy $s = Thread::Semaphore->new();\n$s->down();   # Also known as the semaphore P operation.\n# The guarded section is here\n$s->up();     # Also known as the semaphore V operation.\n\n# Decrement the semaphore only if it would immediately succeed.\nif ($s->downnb()) {\n# The guarded section is here\n$s->up();\n}\n\n# Forcefully decrement the semaphore even if its count goes below 0.\n$s->downforce();\n\n# The default value for semaphore operations is 1\nmy $s = Thread::Semaphore->new($initialvalue);\n$s->down($downvalue);\n$s->up($upvalue);\nif ($s->downnb($downvalue)) {\n...\n$s->up($upvalue);\n}\n$s->downforce($downvalue);\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Semaphores provide a mechanism to regulate access to resources. Unlike locks, semaphores aren't\ntied to particular scalars, and so may be used to control access to anything you care to use\nthem for.\n\nSemaphores don't limit their values to zero and one, so they can be used to control access to\nsome resource that there may be more than one of (e.g., filehandles). Increment and decrement\namounts aren't fixed at one either, so threads can reserve or return multiple resources at once.\n",
                "subsections": []
            },
            "METHODS": {
                "content": "->new()\n->new(NUMBER)\n\"new\" creates a new semaphore, and initializes its count to the specified number (which\nmust be an integer). If no number is specified, the semaphore's count defaults to 1.\n\n->down()\n->down(NUMBER)\nThe \"down\" method decreases the semaphore's count by the specified number (which must be\nan integer >= 1), or by one if no number is specified.\n\nIf the semaphore's count would drop below zero, this method will block until such time\nas the semaphore's count is greater than or equal to the amount you're \"down\"ing the\nsemaphore's count by.\n\nThis is the semaphore \"P operation\" (the name derives from the Dutch word \"pak\", which\nmeans \"capture\" -- the semaphore operations were named by the late Dijkstra, who was\nDutch).\n\n->downnb()\n->downnb(NUMBER)\nThe \"downnb\" method attempts to decrease the semaphore's count by the specified number\n(which must be an integer >= 1), or by one if no number is specified.\n\nIf the semaphore's count would drop below zero, this method will return *false*, and the\nsemaphore's count remains unchanged. Otherwise, the semaphore's count is decremented and\nthis method returns *true*.\n\n->downforce()\n->downforce(NUMBER)\nThe \"downforce\" method decreases the semaphore's count by the specified number (which\nmust be an integer >= 1), or by one if no number is specified. This method does not\nblock, and may cause the semaphore's count to drop below zero.\n\n->downtimed(TIMEOUT)\n->downtimed(TIMEOUT, NUMBER)\nThe \"downtimed\" method attempts to decrease the semaphore's count by 1 or by the\nspecified number within the specified timeout period given in seconds (which must be an\ninteger >= 0).\n\nIf the semaphore's count would drop below zero, this method will block until either the\nsemaphore's count is greater than or equal to the amount you're \"down\"ing the\nsemaphore's count by, or until the timeout is reached.\n\nIf the timeout is reached, this method will return *false*, and the semaphore's count\nremains unchanged. Otherwise, the semaphore's count is decremented and this method\nreturns *true*.\n\n->up()\n->up(NUMBER)\nThe \"up\" method increases the semaphore's count by the number specified (which must be\nan integer >= 1), or by one if no number is specified.\n\nThis will unblock any thread that is blocked trying to \"down\" the semaphore if the \"up\"\nraises the semaphore's count above the amount that the \"down\" is trying to decrement it\nby. For example, if three threads are blocked trying to \"down\" a semaphore by one, and\nanother thread \"up\"s the semaphore by two, then two of the blocked threads (which two is\nindeterminate) will become unblocked.\n\nThis is the semaphore \"V operation\" (the name derives from the Dutch word \"vrij\", which\nmeans \"release\").\n",
                "subsections": []
            },
            "NOTES": {
                "content": "Semaphores created by Thread::Semaphore can be used in both threaded and non-threaded\napplications. This allows you to write modules and packages that potentially make use of\nsemaphores, and that will function in either environment.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "Thread::Semaphore on MetaCPAN: <https://metacpan.org/release/Thread-Semaphore>\n\nCode repository for CPAN distribution: <https://github.com/Dual-Life/Thread-Semaphore>\n\nthreads, threads::shared\n\nSample code in the *examples* directory of this distribution on CPAN.\n",
                "subsections": []
            },
            "MAINTAINER": {
                "content": "Jerry D. Hedden, <jdhedden AT cpan DOT org>\n",
                "subsections": []
            },
            "LICENSE": {
                "content": "This program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
                "subsections": []
            }
        }
    }
}