{"id":25717,"date":"2022-12-13T00:34:35","date_gmt":"2022-12-12T19:04:35","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/"},"modified":"2022-12-13T00:34:35","modified_gmt":"2022-12-12T19:04:35","slug":"solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/","title":{"rendered":"[Solved] bank, 4 atm machine input txt files, syncing information between them with semaphores"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-44490545\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"44490545\" data-parentid=\"44479741\" data-score=\"3\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>I know it&#8217;s tagged c, but since you spammed it in <code>Lounge&lt;C++&gt;<\/code>, let me humor you with C++:<\/p>\n<p><strong><kbd><a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/coliru.stacked-crooked.com\/a\/f08ca056b0401f43\">Live On Coliru<\/a><\/kbd><\/strong><\/p>\n<pre><code>#include &lt;algorithm&gt;\n#include &lt;functional&gt;\n#include &lt;atomic&gt;\n#include &lt;fstream&gt;\n#include &lt;iostream&gt;\n#include &lt;list&gt;\n#include &lt;mutex&gt;\n#include &lt;sstream&gt;\n#include &lt;string&gt;\n#include &lt;thread&gt;\n#include &lt;vector&gt;\n\n\/\/ not thread-aware:\nstruct Bank {\n    struct Account {\n        int id;\n        int password;\n        int balance;\n\n        Account(int id, int password = 0, int balance = 0)\n            : id(id), password(password), balance(balance) { }\n\n        bool operator==(Account const&amp; other) const { return id == other.id; }\n    };\n\n    void remove(int id) {\n        auto&amp; acc = get_unverified(id);\n        accounts.remove(acc);\n    }\n\n    void add(Account const&amp; acc) {\n        if (std::count(accounts.begin(), accounts.end(), acc.id))\n            throw std::runtime_error(\"account with the same id exists\"); \/\/ TODO include id?\n        accounts.push_back(acc);\n    }\n\n    Account&amp; get_unverified(int id) {\n        auto it = std::find(accounts.begin(), accounts.end(), id);\n        if (it != accounts.end())\n            return *it;\n        throw std::runtime_error(\"Account \" + std::to_string(id) + \" doesn't exist\");\n    }\n\n    Account&amp; get(int id, int password) {\n        auto&amp; acc = get_unverified(id);\n        if (acc.password != password)\n            throw std::runtime_error(\"Password for id &lt;\" + std::to_string(id) + \"&gt; is incorrect\");\n        return acc;\n    }\n\n    void status() const {\n        std::cout &lt;&lt; \"*******************************\\n\";\n        std::cout &lt;&lt; \"Bank status: \\n\";\n\n        int totalAmount = 0;\n        for (auto const &amp;acc : accounts) {\n            std::cout &lt;&lt; \"Account: \" &lt;&lt; acc.id &lt;&lt; \", Account password: \" &lt;&lt; acc.password &lt;&lt; \", Balance: \" &lt;&lt; acc.balance\n                &lt;&lt; \"$\\n\";\n            totalAmount += acc.balance;\n        }\n\n        \/\/ Print and Reset bank's balance to zero\n        std::cout &lt;&lt; \"Bank's balance: \" &lt;&lt; totalAmount &lt;&lt; \"\\n\";\n        std::cout &lt;&lt; \"*******************************\\n\";\n    }\n\n  private:\n    std::list&lt;Account&gt; accounts;\n};\n\n\/\/ something to make access guarded:\ntemplate &lt;typename T&gt;\nstruct Locking {\n    template &lt;typename Op&gt;\n    void transactional(Op&amp;&amp; op) {\n        std::lock_guard&lt;std::mutex&gt; lk(_mx);\n        std::forward&lt;Op&gt;(op)(_value);\n    }\n\n  private:\n    std::mutex _mx;\n    T _value;\n};\n\nstatic void bankLoop(Locking&lt;Bank&gt;&amp; safe, std::atomic_bool&amp; keepRunning) {\n    while (keepRunning) {\n        std::this_thread::sleep_for(std::chrono::seconds(1));\n\n        safe.transactional(std::mem_fn(&amp;Bank::status));\n    }\n}\n\nstruct Log {\n    Log() : ofs(\"log.txt\") { } \/\/ TODO fix mode\/fail on existing?\n\n    void Write(std::string const &amp;msg) {\n        std::lock_guard&lt;std::mutex&gt; lk(_mx);\n        ofs &lt;&lt; msg &lt;&lt; \"\\n\";\n    }\n\n  private:\n    std::mutex _mx;\n    std::ofstream ofs;\n} logDescriptor;\n\nstruct Atm {\n    Locking&lt;Bank&gt;&amp; safe;\n    int const fileNum;\n\n    void process(std::string const&amp; fileName) {\n        std::ifstream file(fileName);\n\n        std::string line;\n        while (std::getline(file, line)) {\n            \/\/ totally made up this feature:\n            if (line.empty()) {\n                std::this_thread::sleep_for(std::chrono::milliseconds(200));\n                continue;\n            }\n\n            switch (line[0]) {\n                case 'O': openNewAccount(line); break;\n                case 'D': depositAccount(line); break;\n                case 'W': Withdrawl(line); break;\n                case 'B': Balance(line); break;\n                case 'Q': CloseAccount(line); break;\n                case 'T': TransferAccount(line); break;\n            }\n        }\n\n        std::this_thread::sleep_for(std::chrono::milliseconds(100));\n        file.close();\n    }\n\n  private:\n\n    void TransferAccount(std::string const&amp; msg) {\n        std::cout &lt;&lt; \"Transfering to account... \" &lt;&lt; msg &lt;&lt; \"\\n\";\n\n        safe.transactional([=](Bank&amp; bank) {\n            std::ostringstream msgLog;\n            try {\n                auto const cmd = parseCommand(msg);\n                auto&amp; source = bank.get(cmd.id, cmd.pw);\n                auto&amp; target = bank.get_unverified(cmd.id2);\n\n                source.balance -= cmd.amount;\n                target.balance += cmd.amount;\n\n                msgLog \n                    &lt;&lt; \"&lt;ATM ID: \" &lt;&lt; fileNum &lt;&lt; \"&gt;: \"\n                    &lt;&lt; \"Transfer &lt;\" &lt;&lt; cmd.amount &lt;&lt; \"&gt; \"\n                    &lt;&lt; \"from account &lt;\" &lt;&lt; cmd.id &lt;&lt; \"&gt; \"\n                    &lt;&lt; \"to account &lt;\" &lt;&lt; cmd.id2 &lt;&lt; \"&gt; \"\n                    &lt;&lt; \"new balance is &lt;\" &lt;&lt; source.balance &lt;&lt; \"&gt; \"\n                    &lt;&lt; \"new target account balance is &lt;\" &lt;&lt; target.balance &lt;&lt; \"&gt;\";\n            } catch(std::exception const&amp; e) {\n                msgLog &lt;&lt; \"Error &lt;ATM ID: \" &lt;&lt; fileNum &lt;&lt; \"&gt;: Your transaction failed  - \" &lt;&lt; e.what();\n            }\n            logDescriptor.Write(msgLog.str());\n        });\n    }\n\n    void CloseAccount(std::string const&amp; msg) {\n        std::cout &lt;&lt; \"Closing account... \" &lt;&lt; msg &lt;&lt; \"\\n\";\n        safe.transactional([=](Bank&amp; bank) {\n            std::ostringstream msgLog;\n            try {\n                auto const cmd = parseCommand(msg);\n                auto&amp; acc = bank.get(cmd.id, cmd.pw);\n                auto const balance = acc.balance;\n\n                bank.remove(acc.id);\n\n                msgLog \n                    &lt;&lt; \"&lt;ATM ID: \" &lt;&lt; fileNum &lt;&lt; \"&gt;: \"\n                    &lt;&lt; \"Account &lt;\" &lt;&lt; cmd.id &lt;&lt; \"&gt; is now closed. \"\n                    &lt;&lt; \"Balance was &lt;\" &lt;&lt; balance &lt;&lt; \"&gt;\";\n            } catch(std::exception const&amp; e) {\n                msgLog &lt;&lt; \"Error &lt;ATM ID: \" &lt;&lt; fileNum &lt;&lt; \"&gt;: Your transaction failed  - \" &lt;&lt; e.what();\n            }\n            logDescriptor.Write(msgLog.str());\n        });\n    }\n\n    void depositAccount(std::string const&amp; msg) {\n        std::cout &lt;&lt; \"Depositing to account.. \" &lt;&lt; msg &lt;&lt; \"\\n\";\n        safe.transactional([=](Bank&amp; bank) {\n            std::ostringstream msgLog;\n            try {\n                auto const cmd = parseCommand(msg);\n                auto&amp; acc = bank.get(cmd.id, cmd.pw);\n                acc.balance += cmd.amount;\n\n                msgLog \n                    &lt;&lt; \"&lt;ATM ID: \" &lt;&lt; fileNum &lt;&lt; \"&gt;: \"\n                    &lt;&lt; \"Account &lt;\" &lt;&lt; cmd.id &lt;&lt; \"&gt; \"\n                    &lt;&lt; \"new balance is &lt;\" &lt;&lt; acc.balance &lt;&lt; \"&gt; \"\n                    &lt;&lt; \"after &lt;\" &lt;&lt; cmd.amount &lt;&lt; \"&gt; was deposited\";\n            } catch(std::exception const&amp; e) {\n                msgLog &lt;&lt; \"Error &lt;ATM ID: \" &lt;&lt; fileNum &lt;&lt; \"&gt;: Your transaction failed  - \" &lt;&lt; e.what();\n            }\n            logDescriptor.Write(msgLog.str());\n        });\n    }\n\n    void Withdrawl(std::string const&amp; msg) {\n        std::cout &lt;&lt; \"Withdrawl from account.. \" &lt;&lt; msg &lt;&lt; \"\\n\";\n        safe.transactional([=](Bank&amp; bank) {\n            std::ostringstream msgLog;\n            try {\n                auto const cmd = parseCommand(msg);\n                auto&amp; acc = bank.get(cmd.id, cmd.pw);\n                acc.balance -= cmd.amount;\n\n                msgLog \n                    &lt;&lt; \"&lt;ATM ID: \" &lt;&lt; fileNum &lt;&lt; \"&gt;: \"\n                    &lt;&lt; \"Account &lt;\" &lt;&lt; cmd.id &lt;&lt; \"&gt; \"\n                    &lt;&lt; \"new balance is &lt;\" &lt;&lt; acc.balance &lt;&lt; \"&gt; \"\n                    &lt;&lt; \"after &lt;\" &lt;&lt; cmd.amount &lt;&lt; \"&gt; was Withdrawl\";\n            } catch(std::exception const&amp; e) {\n                msgLog &lt;&lt; \"Error &lt;ATM ID: \" &lt;&lt; fileNum &lt;&lt; \"&gt;: Your transaction failed  - \" &lt;&lt; e.what();\n            }\n            logDescriptor.Write(msgLog.str());\n        });\n    }\n\n    void Balance(std::string const&amp; msg) {\n        std::cout &lt;&lt; \"Balance from account.. \" &lt;&lt; msg &lt;&lt; \"\\n\";\n        safe.transactional([=](Bank&amp; bank) {\n            std::ostringstream msgLog;\n            try {\n                auto const cmd = parseCommand(msg);\n                auto&amp; acc = bank.get(cmd.id, cmd.pw);\n\n                msgLog \n                    &lt;&lt; \"&lt;ATM ID: \" &lt;&lt; fileNum &lt;&lt; \"&gt;: \"\n                    &lt;&lt; \"Account &lt;\" &lt;&lt; cmd.id &lt;&lt; \"&gt; \"\n                    &lt;&lt; \"new balance is &lt;\" &lt;&lt; acc.balance &lt;&lt; \"&gt;\";\n            } catch(std::exception const&amp; e) {\n                msgLog &lt;&lt; \"Error &lt;ATM ID: \" &lt;&lt; fileNum &lt;&lt; \"&gt;: Your transaction failed  - \" &lt;&lt; e.what();\n            }\n            logDescriptor.Write(msgLog.str());\n        });\n    }\n\n    void openNewAccount(std::string const&amp; msg) {\n        std::cout &lt;&lt; \"Opening account... \" &lt;&lt; msg &lt;&lt; \"\\n\";\n        safe.transactional([=](Bank&amp; bank) {\n            std::ostringstream msgLog;\n            try {\n                auto const cmd = parseCommand(msg);\n                Bank::Account const acc(cmd.id, cmd.pw, cmd.amount);\n                bank.add(acc);\n\n                msgLog \n                    &lt;&lt; \"&lt;ATM ID: \" &lt;&lt; fileNum &lt;&lt; \"&gt;: \"\n                    &lt;&lt; \"New account id is &lt;\" &lt;&lt; acc.id &lt;&lt; \"&gt; with passoword &lt;\" &lt;&lt; acc.password &lt;&lt; \"&gt; and initial balance &lt;\" &lt;&lt; acc.balance &lt;&lt; \"&gt;,\"; \/\/ FIXME trailing comma\n            } catch(std::exception const&amp; e) {\n                msgLog &lt;&lt; \"Error &lt;ATM ID: \" &lt;&lt; fileNum &lt;&lt; \"&gt;: Your transaction failed  - \" &lt;&lt; e.what();\n            }\n            logDescriptor.Write(msgLog.str());\n        });\n    }\n\n  private:\n    struct Cmd { int id=-1, pw=-1, amount=0, id2=-1; };\n    static Cmd parseCommand(std::string const&amp; msg) {\n        Cmd result;\n        char discard; \/\/ absorbs command character\n        std::istringstream iss(msg);\n\n        if (!(iss &gt;&gt; discard &gt;&gt; result.id &gt;&gt; result.pw))\n            throw std::runtime_error(\"the command message is invalid\");\n\n        iss &gt;&gt; result.amount &gt;&gt; result.id2;\n\n        return result;\n    }\n};\n\nint main() {\n    std::cout &lt;&lt; \"Please enter the number of ATMs you want: \";\n    int n = 0;\n    if (!(std::cin &gt;&gt; n))\n        throw std::runtime_error(\"Input failed\");\n\n    \/\/ Create bank thread\n    Locking&lt;Bank&gt; bank;\n    std::atomic_bool keepRunning{true};\n    std::thread bankThread(&amp;bankLoop, std::ref(bank), std::ref(keepRunning));\n\n    std::list&lt;std::thread&gt; atmThreads;\n    for (int i = 0; i &lt; n; i++) {\n        atmThreads.emplace_back([&amp;bank, i] {\n            Atm atm { bank, i };\n            atm.process(\"ATM_\" + std::to_string(i) + \"_input_file.txt\");\n        });\n    }\n\n    \/\/ Join ATM threads\n    for (auto &amp;atm : atmThreads)\n        atm.join();\n\n    \/\/ Join bank thread\n    keepRunning = false;\n    bankThread.join();\n}\n<\/code><\/pre>\n<p>Let&#8217;s test it with 1 ATM file<\/p>\n<pre><code>O 123 8888 10\nO 123 8888 10\nW 123 8888 5\nB 123 8888\nB 123 7777\n\nO 234 9999 20\nD 234 9999 50\nB 234 9999\n\nW 123 8888 15\nT 234 9999 30  123\nQ 234 9999\nQ 234 9999\nB 123 what\n<\/code><\/pre>\n<p>It prints<\/p>\n<pre><code>Please enter the number of ATMs you want: 1\nOpening account... O 123 8888 10\nOpening account... O 123 8888 10\nWithdrawl from account.. W 123 8888 5\nBalance from account.. B 123 8888\nBalance from account.. B 123 7777\nOpening account... O 234 9999 20\nDepositing to account.. D 234 9999 50\nBalance from account.. B 234 9999\nWithdrawl from account.. W 123 8888 15\nTransfering to account... T 234 9999 30  123\nClosing account... Q 234 9999\nClosing account... Q 234 9999\nBalance from account.. B 123 what\n*******************************\nBank status: \nAccount: 123, Account password: 8888, Balance: 20$\nBank's balance: 20\n*******************************\n<\/code><\/pre>\n<p>And <code>log.txt<\/code> ends up like:<\/p>\n<pre><code>&lt;ATM ID: 0&gt;: New account id is &lt;123&gt; with passoword &lt;8888&gt; and initial balance &lt;10&gt;,\nError &lt;ATM ID: 0&gt;: Your transaction failed  - account with the same id exists\n&lt;ATM ID: 0&gt;: Account &lt;123&gt; new balance is &lt;5&gt; after &lt;5&gt; was Withdrawl\n&lt;ATM ID: 0&gt;: Account &lt;123&gt; new balance is &lt;5&gt;\nError &lt;ATM ID: 0&gt;: Your transaction failed  - Password for id &lt;123&gt; is incorrect\n&lt;ATM ID: 0&gt;: New account id is &lt;234&gt; with passoword &lt;9999&gt; and initial balance &lt;20&gt;,\n&lt;ATM ID: 0&gt;: Account &lt;234&gt; new balance is &lt;70&gt; after &lt;50&gt; was deposited\n&lt;ATM ID: 0&gt;: Account &lt;234&gt; new balance is &lt;70&gt;\n&lt;ATM ID: 0&gt;: Account &lt;123&gt; new balance is &lt;-10&gt; after &lt;15&gt; was Withdrawl\n&lt;ATM ID: 0&gt;: Transfer &lt;30&gt; from account &lt;234&gt; to account &lt;123&gt; new balance is &lt;40&gt; new target account balance is &lt;20&gt;\n&lt;ATM ID: 0&gt;: Account &lt;234&gt; is now closed. Balance was &lt;40&gt;\nError &lt;ATM ID: 0&gt;: Your transaction failed  - Account 234 doesn't exist\nError &lt;ATM ID: 0&gt;: Your transaction failed  - the command message is invalid\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">1<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved bank, 4 atm machine input txt files, syncing information between them with semaphores <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] I know it&#8217;s tagged c, but since you spammed it in Lounge&lt;C++&gt;, let me humor you with C++: Live On Coliru #include &lt;algorithm&gt; #include &lt;functional&gt; #include &lt;atomic&gt; #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;list&gt; #include &lt;mutex&gt; #include &lt;sstream&gt; #include &lt;string&gt; #include &lt;thread&gt; #include &lt;vector&gt; \/\/ not thread-aware: struct Bank { struct Account { int id; &#8230; <a title=\"[Solved] bank, 4 atm machine input txt files, syncing information between them with semaphores\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/\" aria-label=\"More on [Solved] bank, 4 atm machine input txt files, syncing information between them with semaphores\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[324,2110,493,1991,443],"class_list":["post-25717","post","type-post","status-publish","format-standard","hentry","category-solved","tag-c","tag-centos","tag-file","tag-semaphore","tag-unix"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] bank, 4 atm machine input txt files, syncing information between them with semaphores - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] bank, 4 atm machine input txt files, syncing information between them with semaphores - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] I know it&#8217;s tagged c, but since you spammed it in Lounge&lt;C++&gt;, let me humor you with C++: Live On Coliru #include &lt;algorithm&gt; #include &lt;functional&gt; #include &lt;atomic&gt; #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;list&gt; #include &lt;mutex&gt; #include &lt;sstream&gt; #include &lt;string&gt; #include &lt;thread&gt; #include &lt;vector&gt; \/\/ not thread-aware: struct Bank { struct Account { int id; ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-12T19:04:35+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] bank, 4 atm machine input txt files, syncing information between them with semaphores\",\"datePublished\":\"2022-12-12T19:04:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/\"},\"wordCount\":62,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"c++\",\"centos\",\"file\",\"semaphore\",\"unix\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/\",\"name\":\"[Solved] bank, 4 atm machine input txt files, syncing information between them with semaphores - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-12-12T19:04:35+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] bank, 4 atm machine input txt files, syncing information between them with semaphores\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] bank, 4 atm machine input txt files, syncing information between them with semaphores - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] bank, 4 atm machine input txt files, syncing information between them with semaphores - JassWeb","og_description":"[ad_1] I know it&#8217;s tagged c, but since you spammed it in Lounge&lt;C++&gt;, let me humor you with C++: Live On Coliru #include &lt;algorithm&gt; #include &lt;functional&gt; #include &lt;atomic&gt; #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;list&gt; #include &lt;mutex&gt; #include &lt;sstream&gt; #include &lt;string&gt; #include &lt;thread&gt; #include &lt;vector&gt; \/\/ not thread-aware: struct Bank { struct Account { int id; ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/","og_site_name":"JassWeb","article_published_time":"2022-12-12T19:04:35+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] bank, 4 atm machine input txt files, syncing information between them with semaphores","datePublished":"2022-12-12T19:04:35+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/"},"wordCount":62,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["c++","centos","file","semaphore","unix"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/","url":"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/","name":"[Solved] bank, 4 atm machine input txt files, syncing information between them with semaphores - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-12-12T19:04:35+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-bank-4-atm-machine-input-txt-files-syncing-information-between-them-with-semaphores\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] bank, 4 atm machine input txt files, syncing information between them with semaphores"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/25717","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=25717"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/25717\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=25717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=25717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=25717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}