Created
May 6, 2022 16:57
-
-
Save whitespy/4862184fa2b1bc3d837ca36604f265e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "uuid": "941a4e17-eaa8-4f0e-a4ef-39c502eeb6b2", | |
| "type": "code", | |
| "subtype": "autograded_answer", | |
| "points": null, | |
| "source": [ | |
| "import threading\n", | |
| "\n", | |
| "### BEGIN SOLUTION\n", | |
| "a = 0\n", | |
| "threads = []\n", | |
| "### END SOLUTION\n", | |
| "\n", | |
| "def x():\n", | |
| " global a\n", | |
| " for i in range(100_000):\n", | |
| " a += 1\n", | |
| "\n", | |
| "for j in range(10):\n", | |
| " thread = threading.Thread(target=x)\n", | |
| " threads.append(thread)\n", | |
| " thread.start()\n", | |
| "\n", | |
| "### BEGIN SOLUTION\n", | |
| "for thread in threads:\n", | |
| " thread.join()\n", | |
| "### END SOLUTION\n", | |
| "\n" | |
| ], | |
| "outputs": null, | |
| "tests_cells": [ | |
| { | |
| "uuid": "e89d559f-69d4-4834-8053-859183c7e9bc", | |
| "type": "code", | |
| "subtype": "autograder_tests", | |
| "points": 10, | |
| "source": [ | |
| "### BEGIN HIDDEN TESTS\n", | |
| "assert a == 1_000_000\n", | |
| "### END HIDDEN TESTS\n", | |
| "assert 1 == 1\n" | |
| ], | |
| "outputs": null | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment