User Tools

Site Tools


os_cp:2024:prog_assignment

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
os_cp:2024:prog_assignment [2024/05/15 22:24] – utworzono jkonczakos_cp:2024:prog_assignment [2024/06/05 23:38] (current) – jkonczak
Line 18: Line 18:
 redundancy will lower the grade. redundancy will lower the grade.
  
-The deadline for the assignment is **02.06.2024** (AoE). Please send the+The deadline for the assignment is 02.06.2024 (AoE). Please send the
 solutions to me as an attachment to an e-mail message with the subject solutions to me as an attachment to an e-mail message with the subject
 beginning with ''[OSCP]''. beginning with ''[OSCP]''.
 +
 +**The tests that I used to tell if your code behaves as expected are available [[https://www.cs.put.poznan.pl/jkonczak/misc/oscp-prog-check.tar.xz|here]].**
  
 <code c header.h> <code c header.h>
Line 70: Line 72:
  * The identifiers shall be consecutive numbers starting from 0.  * The identifiers shall be consecutive numbers starting from 0.
  * Identifier 0 must always be the main thread.  * Identifier 0 must always be the main thread.
 + *
 + * (clarification added on 28 May) thread identifiers must not be 
 + * reused; when a thread with an identifier ID terminates, no new
 + * thread may get the identifier ID.
  *   * 
  * Each thread must have a message queue in that at most   * Each thread must have a message queue in that at most 
Line 181: Line 187:
 <code c> <code c>
 #include "header.h" #include "header.h"
 +#include <stdatomic.h>
 #include <stdint.h> #include <stdint.h>
 #include <stdio.h> #include <stdio.h>
Line 187: Line 194:
  
 struct thread_msg{ struct thread_msg{
-    int uc;+    atomic_int uc;
     char * txt;     char * txt;
 }; };
Line 252: Line 259:
     thread_gather(senders, 2, msgs);     thread_gather(senders, 2, msgs);
     printf("%s%s\n", msgs[0]->txt, msgs[1]->txt);     printf("%s%s\n", msgs[0]->txt, msgs[1]->txt);
 +    thread_msg_dec_use_count(msgs[0]);
 +    thread_msg_dec_use_count(msgs[1]);
          
     // send a message to the main thread     // send a message to the main thread
Line 277: Line 286:
  
 void thread_msg_dec_use_count(thread_msg* msg){ void thread_msg_dec_use_count(thread_msg* msg){
-    if(!msg->uc--){+    if(!--msg->uc){
         free(msg->txt);         free(msg->txt);
         free(msg);         free(msg);
os_cp/2024/prog_assignment.1715811842.txt.gz · Last modified: (external edit)