Dydaktyka
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Ćwiczenia 13, grupa cz. 14-16, 9. czerwca 2022 ###### tags: `SYK21` `ćwiczenia` `pwit` ## Deklaracje Gotowość rozwiązania zadania należy wyrazić poprzez postawienie X w odpowiedniej kolumnie! Jeśli pożądasz zreferować dane zadanie (co najwyżej jedno!) w trakcie dyskusji oznacz je znakiem ==X== na żółtym tle. **UWAGA: Tabelkę wolno edytować tylko wtedy, gdy jest na zielonym tle!** :::danger | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | | ----------------------:| ----- | --- | --- | --- | --- | --- | --- | --- | --- | Kamil Banaś | | | | | | | | | | Mateusz Burdyna | | | | | | | | | | Dariusz Ciesielski | | | | | | | | | | Dawid Dudek | X | X | X | X | X | X | X | X | | Mikołaj Dworszczak | | | | | | | | | | Przemysław Grochal | X | X | X | X | X | X | | | | Adam Jarząbek | X | X | | X | X | | | | | Anna Karykowska | X | X | X | X | X | | | | | Oleś Kulczewicz | | | | | | | | | | Pola Marciniak | X | X | X | X | X | X | X | | | Mikołaj Mroziuk | X | X |==X==| X | X | X | X | X | | Marcelina Oset | X | X | X | X | | X | | | | Natalia Piasta | X | X | X | X | X | X | X | | | Krzysztof Piekarczyk | ==X== | X | X | X | X | X | | | | Marcin Płaza | X | ==X== | X | X | X | X | X | X | | Paweł Richert | X | X | X | X | X | X | X | X | | Rafał Starypan | X | X | X | X | X | | | | | Dawid Strojek | X | X | X | X | X | | | | | Mateusz Suszek | X | X | X | X | X | X | X | | | Wojciech Śniady | X | X | X | X | X | X | X | X | | Volha Tsekalo | x | x | x | x | x | x | | | | Yana Vashkevich | x | x | x | x | x | | | | | Konrad Woźniak | X | X | X | X | X | X | X | X | | Natalia Czerep | | | | | | | | | | Joanna Stachowicz | X | X | X | X |==X==| X | X | X | | ::: Tu można do-deklarować zadanie 7 z listy 12.: - - :::info **Uwaga:** Po rozwiązaniu zadania należy zmienić kolor nagłówka na zielony. ::: ## Zadanie 1 :::success Autor: Krzysztof Piekarczyk ::: ![](https://i.imgur.com/txEC1Qz.png) *Sytuacja wyścigu ma miejsce, kiedy możemy otrzymać różne wartości współdzielonych przez procesy zmiennych w zależności od tego, w jakiej kolejności wykonujemy instrukcje.* W przypadku tego zadania możemy otrzymać 2 wartości: **1** oraz **2** Ad **(1)** (będzie to w sytuacji, kiedy będą powtarzane analogiczne instrukcje przez procesory P1 i P2): $$regP1 \leftarrow counter [counter = 0]\\ regP2 \leftarrow counter [counter = 0]\\ regP1 \leftarrow regP1 + 1 [regP1 = 1]\\ regP2 \leftarrow regP2 + 1 [regP2 = 1]\\ counter \leftarrow regP1 [counter = 1]\\ counter \leftarrow regP2 [counter = 1]$$ Ad **(2)** (sytuacja, gdy najpierw wykonujemy instrukcje dla P1, a potem dla P2) $$regP1 \leftarrow counter [counter = 0]\\ regP1 \leftarrow regP1 + 1 [regP1 = 1]\\ counter \leftarrow regP1 [counter = 1]\\ regP2 \leftarrow counter [counter = 1]\\ regP2 \leftarrow regP2 + 1 [regP2 = 2]\\ counter \leftarrow regP2 [counter = 2]$$ Więc mamy tutaj sytuację wyścigu. ## Zadanie 2 :::success Autor: Marcin Płaza ::: ![](https://i.imgur.com/5DaYYNk.png) P1 wczytuje c=0 P2 wykonuje petle 49 razy P1 zapisuje c=1 P2 wczytuje c=1 P1 wykona petle do konca P2 zapisze c=2 Najmniejsza możliwa wartość zmiennej counter wynosi 2, dzieje się to wtedy, gdy pierwszy proces wczytuje counter o wartości 0, drugi wykonuje pętle, pierwszy zapisuje counter 1, drugi wczytuje 1, pierwszy wykonuje pętle, drugi zapisuje 2. Największa możliwość zmiennej counter wynosi 100, wtedy gdy pierwszy proces wykonuje całość, a następnie drugi całość. ## Zadanie 3 :::success Autor: Mikołaj Mroziuk ::: ![](https://i.imgur.com/sMoFEfv.png) ### warunki 1. **Wzajemne wykluczanie** Jeśli proces $P_i$ działa w swojej sekcji krytycznej, to żaden inny proces nie działa w sekcji krytycznej. 2. **Postęp** Jeśli żaden proces nie działa w sekcji krytycznej oraz istnieją procesy, które chcą wejść do sekcji krytycznych, wybór nie może odwlekany w nieskończoność. 3. **Ograniczone czekanie** Musi istnieć wartość graniczna liczby wejść innych procesów do ich sekcji krytycznych po tym, gdy dany proces zgłosił chęć wejścia do swojej sekcji krytycznej i zanim uzyskał na to pozwolenie. ### uzasadnienie 1. Wzajemne wykluczanie sekcja krytyczna wątku zostanie uruchomiona dopiero po zakończeniu sekcji w drugim wątku (gdy flaga będzie ustawiona na fałsz) 2. Postęp jeden wątek oczekujący na wejście do sekcji krytycznej może ustawić swoją flagę na wartość true i zostać wywłaszczony. W międzyczasie drugi wątek może zakończyć działanie w sekcji krytycznej, ustawić flagę na false i ponownie próbować wejść do sekcji krytycznej ustawiając znowu swoją flagę na true. Wówczas dochodzi do sytuacji patowej - obie flagi są ustawione na true 3. Ograniczone czekanie wątek oczekujący na dostęp do sekcji krytycznej blokuje dostęp drugiemu wątkowi ## Zadanie 4 :::success Autor: Adam Jarząbek ::: Warunek wzajemnego wykluczania: Warunek ten oznacza, że P0 i P1 nie będą jednocześnie w sekcji krytycznej. Jest on spełniony, poniważ jak wykonuje się P0 to zmienna turn jest ustawiona na 0 i analogicznie jak wykonuje się P1 to zmienna turn jest ustawiona na 1. Postęp: Jeśli postęp nie jest spełniony to zachodzi: flag[0]==true && turn == 1 oraz flag[1] == true && turn == 0 Co jest oczywistym fałszem Ograniczone czekanie: Jest spełniony, ponieważ procesy wzajemnie ustawiają turn na id przeciwnika. ## Zadanie 5 :::success Autor: Joanna Stachowicz ![](https://i.imgur.com/hhHwjR9.jpg) ![](https://i.imgur.com/9gC7kgo.jpg) ::: ## Zadanie 6 :::success Autor: Dawid Dudek ::: ## Zadanie 6 ![](https://i.imgur.com/fPWSUbB.png) ``` void lock(){ flag[me] = true; turn = me while(flag[other] && turn == other) } ``` Nie ma wzajemnego wykluczenia: A: flag[A] = true B: flag[B] = true A: turn = A A: wchodzi do sekcji krytyczne B: turn = B B: wchodzi do sekcji krytycznej Deadlock: nie może wystąpić bo turn jest tylko w jednym stanie na raz Starvation: A: flag[A] = true B: flag[B] = true B: turn = B B: sleep A: turn = A B: budzi się i widzi, że nie może wejść A: wchodzi do sekcji krytycznej i będzie do niej już zawsze wchodzić. ## Zadanie 7 :::success Autor: Natalia Piasta ::: ![](https://i.imgur.com/3UENTPV.png) * Wzajemne wykluczenie * Podczas wykonywania się sekcji krytycznej procesu (tj. tylko gdy `turn = my_id`), to wtedy nie może w tym samym czasie wykonywać się inny proces. Wynika to z tego, że `turn` zmienia się dopiero w funckji `unlock`. * Postęp * Jeżeli będziemy mieć dwa procesy, które czekają na dostęp do sekcji krytycznej, tj. flaga `=true`, to proces aktualny odblokuje na etapie `turn != my_id` wartość flagi, dzięki czemu to ten drugi uzyska dostęp do sekcji krytycznej. * Ograniczone czekanie * Jeśli proces P0 znajduje się na etapie `while(turn!my_id);`, tj. nie dostał dostepu, ze względu na ustawienie wartości `false`, to wtedy proces P1 jest wykonywany gdyż w `unlock, turn = 1`. Można więc powiedzieć, że zachowuje dostęp do sekcji krytycznej tylko dla siebie. ## Zadanie 8 :::success Autor: Konrad Woźniak ::: ![](https://i.imgur.com/OBh1Yy1.png) ```c= boolean TestAndSet (boolean *target) { boolean rv = *target; *target = true; return rv; } void lock(int my_id) { while (TestAndSet(&lock)); } void unlock(int my_id) { lock = false; } ``` *TestAndSet to instrukcja atomowa.* **Warunek postępu** - zachowany Gdy jeden wątek ustawi lock = false, to oba wątki mogą ponownie wejść **Warunek ograniczonego czekania** - niezachowany ``` P1 : lock P0 : czeka w while (TestAndSet(&lock)); P1 : unlock P1 : lock ``` ## Zadanie 9 :::danger Autor: do-deklarować :::

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully