Lab5
This commit is contained in:
+6
-2
@@ -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)
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#include <wait.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
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;
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#include <stdio.h>
|
||||
#include <wait.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
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;
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
Binary file not shown.
@@ -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
|
||||
|
||||
Binary file not shown.
@@ -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
|
||||
|
||||
@@ -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 = :
|
||||
|
||||
Reference in New Issue
Block a user