diff --git a/CMakeLists.txt b/CMakeLists.txt index 74bf536..57bd749 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,11 @@ cmake_minimum_required(VERSION 3.29) project(OS C) + set(CMAKE_C_STANDARD 11) -add_executable(OS main.c - Lab4/ex1.c) +SET(GCC_COVERAGE_COMPILE_FLAGS "-pthread") + + +add_executable(OS + Lab5/ex4.c) diff --git a/Lab5/ex1.c b/Lab5/ex1.c new file mode 100644 index 0000000..3404c27 --- /dev/null +++ b/Lab5/ex1.c @@ -0,0 +1,37 @@ +#include + +#include +#include + +/* +pthread_t phread_self(void); + +void * start_routine(void * arg); +int pthread_create(pthread_t * thread, const pthread_attr_t * attr, + void *(start_routine)(void *), void * arg); +void pthread_exit(void *retval); +*/ + +void * start_routine(void * arg) { + int pid = pthread_self(); + printf("%d\n",pid); + return NULL; +} + +int main() { + + int val1 = 5; + int val2 = 11; + + pthread_t thread1; + pthread_t thread2; + pthread_create(&thread1, NULL, &start_routine, NULL); + pthread_create(&thread2, NULL, &start_routine, NULL); + + + + printf("Program started!\n"); + + pthread_exit(NULL); + return 0; +} \ No newline at end of file diff --git a/Lab5/ex2-3.c b/Lab5/ex2-3.c new file mode 100644 index 0000000..ca14f08 --- /dev/null +++ b/Lab5/ex2-3.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +/* +pthread_t phread_self(void); + +void * start_routine(void * arg); +int pthread_create(pthread_t * thread, const pthread_attr_t * attr, + void *(start_routine)(void *), void * arg); +void pthread_exit(void *retval); +*/ + +int globalVar = 5; + +void * start_routine(void * arg) { + //int pid = pthread_self(); + //printf("%d\n",pid); + globalVar += 1; + printf("%d\n",globalVar); + pthread_exit(NULL); +} + +int main() { + + int val1 = 5; + int val2 = 11; + + pthread_t thread1; + pthread_t thread2; + + pthread_create(&thread1, NULL, &start_routine, NULL); + pthread_join(thread1, NULL); + pthread_create(&thread2, NULL, &start_routine, NULL); + pthread_join(thread2, NULL); + + + //printf("%d\n",globalVar); + + printf("Program started!\n"); + + + + + return 0; +} \ No newline at end of file diff --git a/Lab5/ex4.c b/Lab5/ex4.c new file mode 100644 index 0000000..6fd43ca --- /dev/null +++ b/Lab5/ex4.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include + +/* +pthread_t phread_self(void); + +void * start_routine(void * arg); +int pthread_create(pthread_t * thread, const pthread_attr_t * attr, + void *(start_routine)(void *), void * arg); +void pthread_exit(void *retval); +*/ + +int globalVar = 5; + +void * start_routine(void * arg) { + //int pid = pthread_self(); + //printf("%d\n",pid); + globalVar += 1; + printf("%d\n",globalVar); + pthread_exit(NULL); +} + +int main() { + + int val1 = 5; + int val2 = 11; + + pthread_t threads[1000]; + + pthread_t thread1; + pthread_t thread2; + + for (int i = 0; i < 1000; ++i){ + pthread_create(&threads[i], NULL, &start_routine, NULL); + pthread_join(threads[i], NULL); + } + + pthread_create(&thread1, NULL, &start_routine, NULL); + pthread_join(thread1, NULL); + pthread_create(&thread2, NULL, &start_routine, NULL); + pthread_join(thread2, NULL); + + + //printf("%d\n",globalVar); + + printf("Program started!\n"); + + + + + return 0; +} \ No newline at end of file diff --git a/cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-b4aa26cc6c7066b9c18c.json b/cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-b4aa26cc6c7066b9c18c.json deleted file mode 100644 index fa254dd..0000000 --- a/cmake-build-debug/.cmake/api/v1/reply/codemodel-v2-b4aa26cc6c7066b9c18c.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "configurations" : - [ - { - "directories" : - [ - { - "build" : ".", - "jsonFile" : "directory-.-Debug-f5ebdc15457944623624.json", - "minimumCMakeVersion" : - { - "string" : "3.29" - }, - "projectIndex" : 0, - "source" : ".", - "targetIndexes" : - [ - 0 - ] - } - ], - "name" : "Debug", - "projects" : - [ - { - "directoryIndexes" : - [ - 0 - ], - "name" : "OS", - "targetIndexes" : - [ - 0 - ] - } - ], - "targets" : - [ - { - "directoryIndex" : 0, - "id" : "OS::@6890427a1f51a3e7e1df", - "jsonFile" : "target-OS-Debug-0afab8c539ea962edde8.json", - "name" : "OS", - "projectIndex" : 0 - } - ] - } - ], - "kind" : "codemodel", - "paths" : - { - "build" : "/home/emil/CLionProjects/OS/cmake-build-debug", - "source" : "/home/emil/CLionProjects/OS" - }, - "version" : - { - "major" : 2, - "minor" : 7 - } -} diff --git a/cmake-build-debug/.cmake/api/v1/reply/index-2024-09-17T14-47-23-0292.json b/cmake-build-debug/.cmake/api/v1/reply/index-2024-09-17T14-47-23-0292.json deleted file mode 100644 index 9476882..0000000 --- a/cmake-build-debug/.cmake/api/v1/reply/index-2024-09-17T14-47-23-0292.json +++ /dev/null @@ -1,108 +0,0 @@ -{ - "cmake" : - { - "generator" : - { - "multiConfig" : false, - "name" : "Ninja" - }, - "paths" : - { - "cmake" : "/home/emil/Downloads/CLion-2024.2.1/clion-2024.2.1/bin/cmake/linux/x64/bin/cmake", - "cpack" : "/home/emil/Downloads/CLion-2024.2.1/clion-2024.2.1/bin/cmake/linux/x64/bin/cpack", - "ctest" : "/home/emil/Downloads/CLion-2024.2.1/clion-2024.2.1/bin/cmake/linux/x64/bin/ctest", - "root" : "/home/emil/Downloads/CLion-2024.2.1/clion-2024.2.1/bin/cmake/linux/x64/share/cmake-3.29" - }, - "version" : - { - "isDirty" : false, - "major" : 3, - "minor" : 29, - "patch" : 6, - "string" : "3.29.6", - "suffix" : "" - } - }, - "objects" : - [ - { - "jsonFile" : "codemodel-v2-b4aa26cc6c7066b9c18c.json", - "kind" : "codemodel", - "version" : - { - "major" : 2, - "minor" : 7 - } - }, - { - "jsonFile" : "cache-v2-ff2113fa112ac8cc3809.json", - "kind" : "cache", - "version" : - { - "major" : 2, - "minor" : 0 - } - }, - { - "jsonFile" : "cmakeFiles-v1-b92a4e5b6a05c81ff658.json", - "kind" : "cmakeFiles", - "version" : - { - "major" : 1, - "minor" : 0 - } - }, - { - "jsonFile" : "toolchains-v1-7605d64beb456dcb5b75.json", - "kind" : "toolchains", - "version" : - { - "major" : 1, - "minor" : 0 - } - } - ], - "reply" : - { - "cache-v2" : - { - "jsonFile" : "cache-v2-ff2113fa112ac8cc3809.json", - "kind" : "cache", - "version" : - { - "major" : 2, - "minor" : 0 - } - }, - "cmakeFiles-v1" : - { - "jsonFile" : "cmakeFiles-v1-b92a4e5b6a05c81ff658.json", - "kind" : "cmakeFiles", - "version" : - { - "major" : 1, - "minor" : 0 - } - }, - "codemodel-v2" : - { - "jsonFile" : "codemodel-v2-b4aa26cc6c7066b9c18c.json", - "kind" : "codemodel", - "version" : - { - "major" : 2, - "minor" : 7 - } - }, - "toolchains-v1" : - { - "jsonFile" : "toolchains-v1-7605d64beb456dcb5b75.json", - "kind" : "toolchains", - "version" : - { - "major" : 1, - "minor" : 0 - } - } - } -} diff --git a/cmake-build-debug/.cmake/api/v1/reply/target-OS-Debug-0afab8c539ea962edde8.json b/cmake-build-debug/.cmake/api/v1/reply/target-OS-Debug-0afab8c539ea962edde8.json deleted file mode 100644 index 3c62044..0000000 --- a/cmake-build-debug/.cmake/api/v1/reply/target-OS-Debug-0afab8c539ea962edde8.json +++ /dev/null @@ -1,107 +0,0 @@ -{ - "artifacts" : - [ - { - "path" : "OS" - } - ], - "backtrace" : 1, - "backtraceGraph" : - { - "commands" : - [ - "add_executable" - ], - "files" : - [ - "CMakeLists.txt" - ], - "nodes" : - [ - { - "file" : 0 - }, - { - "command" : 0, - "file" : 0, - "line" : 6, - "parent" : 0 - } - ] - }, - "compileGroups" : - [ - { - "compileCommandFragments" : - [ - { - "fragment" : "-g -std=gnu11 -fdiagnostics-color=always" - } - ], - "language" : "C", - "languageStandard" : - { - "backtraces" : - [ - 1 - ], - "standard" : "11" - }, - "sourceIndexes" : - [ - 0, - 1 - ] - } - ], - "id" : "OS::@6890427a1f51a3e7e1df", - "link" : - { - "commandFragments" : - [ - { - "fragment" : "-g", - "role" : "flags" - }, - { - "fragment" : "", - "role" : "flags" - } - ], - "language" : "C" - }, - "name" : "OS", - "nameOnDisk" : "OS", - "paths" : - { - "build" : ".", - "source" : "." - }, - "sourceGroups" : - [ - { - "name" : "Source Files", - "sourceIndexes" : - [ - 0, - 1 - ] - } - ], - "sources" : - [ - { - "backtrace" : 1, - "compileGroupIndex" : 0, - "path" : "main.c", - "sourceGroupIndex" : 0 - }, - { - "backtrace" : 1, - "compileGroupIndex" : 0, - "path" : "Lab4/ex1.c", - "sourceGroupIndex" : 0 - } - ], - "type" : "EXECUTABLE" -} diff --git a/cmake-build-debug/.ninja_deps b/cmake-build-debug/.ninja_deps index 645169b..c3e25a2 100644 Binary files a/cmake-build-debug/.ninja_deps and b/cmake-build-debug/.ninja_deps differ diff --git a/cmake-build-debug/.ninja_log b/cmake-build-debug/.ninja_log index cee0fc0..ead96b2 100644 --- a/cmake-build-debug/.ninja_log +++ b/cmake-build-debug/.ninja_log @@ -1,8 +1,11 @@ # ninja log v6 -1 28 1726584631568330806 CMakeFiles/OS.dir/main.c.o 597d2975f9346988 -1 40 1726584631568330806 CMakeFiles/OS.dir/Lab4/ex1.c.o fdfe48b329a854c3 -1 52 1726584695761745762 CMakeFiles/OS.dir/Lab4/ex1.c.o fdfe48b329a854c3 -1 59 1726584757955159622 CMakeFiles/OS.dir/Lab4/ex1.c.o fdfe48b329a854c3 -1 59 1726584793091868090 CMakeFiles/OS.dir/Lab4/ex1.c.o fdfe48b329a854c3 -1 62 1726584899315318179 CMakeFiles/OS.dir/main.c.o 597d2975f9346988 +1 59 1727194503928197251 CMakeFiles/OS.dir/Lab5/ex2-3.c.o 3ac11e55017104db +1 69 1727194450713397978 CMakeFiles/OS.dir/Lab5/ex2.c.o aaf388779ce03a6e +1 54 1727193068898104463 CMakeFiles/OS.dir/Lab5/ex1.c.o 87ce1149fbd620b +1 81 1727191541519747212 CMakeFiles/OS.dir/Lab4/ex1.c.o fdfe48b329a854c3 1 50 1726585076082163985 CMakeFiles/OS.dir/main.c.o 597d2975f9346988 +1 31 1727195105069329767 build.ninja 102e4adb4b6285fe +59 91 1727194503984862096 OS 7e7768c095bc6d8a +1 36 1727195105069329767 build.ninja 102e4adb4b6285fe +0 63 1727195105082663185 CMakeFiles/OS.dir/Lab5/ex4.c.o 60daafb2653af2a5 +63 96 1727195105142663566 OS 5ac1e89d9f8b3dbb diff --git a/cmake-build-debug/CMakeFiles/OS.dir/Lab4/ex1.c.o b/cmake-build-debug/CMakeFiles/OS.dir/Lab4/ex1.c.o index 3fbb236..8a84c8d 100644 Binary files a/cmake-build-debug/CMakeFiles/OS.dir/Lab4/ex1.c.o and b/cmake-build-debug/CMakeFiles/OS.dir/Lab4/ex1.c.o differ diff --git a/cmake-build-debug/Testing/Temporary/LastTest.log b/cmake-build-debug/Testing/Temporary/LastTest.log index 5e86914..28fb3ad 100644 --- a/cmake-build-debug/Testing/Temporary/LastTest.log +++ b/cmake-build-debug/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: Sep 24 17:47 MSK +Start testing: Sep 24 19:25 MSK ---------------------------------------------------------- -End testing: Sep 24 17:47 MSK +End testing: Sep 24 19:25 MSK diff --git a/cmake-build-debug/build.ninja b/cmake-build-debug/build.ninja index fac4a29..aa70532 100644 --- a/cmake-build-debug/build.ninja +++ b/cmake-build-debug/build.ninja @@ -49,17 +49,11 @@ cmake_ninja_workdir = /home/emil/CLionProjects/OS/cmake-build-debug/ build cmake_object_order_depends_target_OS: phony || . -build CMakeFiles/OS.dir/main.c.o: C_COMPILER__OS_unscanned_Debug /home/emil/CLionProjects/OS/main.c || cmake_object_order_depends_target_OS - DEP_FILE = CMakeFiles/OS.dir/main.c.o.d +build CMakeFiles/OS.dir/Lab5/ex4.c.o: C_COMPILER__OS_unscanned_Debug /home/emil/CLionProjects/OS/Lab5/ex4.c || cmake_object_order_depends_target_OS + DEP_FILE = CMakeFiles/OS.dir/Lab5/ex4.c.o.d FLAGS = -g -std=gnu11 -fdiagnostics-color=always OBJECT_DIR = CMakeFiles/OS.dir - OBJECT_FILE_DIR = CMakeFiles/OS.dir - -build CMakeFiles/OS.dir/Lab4/ex1.c.o: C_COMPILER__OS_unscanned_Debug /home/emil/CLionProjects/OS/Lab4/ex1.c || cmake_object_order_depends_target_OS - DEP_FILE = CMakeFiles/OS.dir/Lab4/ex1.c.o.d - FLAGS = -g -std=gnu11 -fdiagnostics-color=always - OBJECT_DIR = CMakeFiles/OS.dir - OBJECT_FILE_DIR = CMakeFiles/OS.dir/Lab4 + OBJECT_FILE_DIR = CMakeFiles/OS.dir/Lab5 # ============================================================================= @@ -69,7 +63,7 @@ build CMakeFiles/OS.dir/Lab4/ex1.c.o: C_COMPILER__OS_unscanned_Debug /home/emil/ ############################################# # Link the executable OS -build OS: C_EXECUTABLE_LINKER__OS_Debug CMakeFiles/OS.dir/main.c.o CMakeFiles/OS.dir/Lab4/ex1.c.o +build OS: C_EXECUTABLE_LINKER__OS_Debug CMakeFiles/OS.dir/Lab5/ex4.c.o FLAGS = -g OBJECT_DIR = CMakeFiles/OS.dir POST_BUILD = :