CoolVeryVery 2 veckor sedan
incheckning
409450b215
6 ändrade filer med 129 tillägg och 0 borttagningar
  1. 27 0
      .vscode/launch.json
  2. 5 0
      .vscode/settings.json
  3. 7 0
      .vscode/task.json
  4. 28 0
      .vscode/tasks.json
  5. BIN
      main
  6. 62 0
      main.c

+ 27 - 0
.vscode/launch.json

@@ -0,0 +1,27 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "name": "(gdb) Launch",
+            "type": "cppdbg",
+            "request": "launch",
+            "program": "${workspaceRoot}/main",
+            "args": [],
+            "stopAtEntry": false,
+            "cwd": "${workspaceRoot}",
+            "environment": [],
+            "MIMode": "gdb",
+            "miDebuggerPath": "/usr/bin/gdb",
+            "setupCommands": [
+                {
+                    "description": "Enable pretty-printing for gdb",
+                    "text": "-enable-pretty-printing",
+                    "ignoreFailures": false
+                }
+            ]
+        }
+    ]
+}

+ 5 - 0
.vscode/settings.json

@@ -0,0 +1,5 @@
+{
+    "files.associations": {
+        "stdio.h": "c"
+    }
+}

+ 7 - 0
.vscode/task.json

@@ -0,0 +1,7 @@
+{
+    "version": "0.1.0",
+    "command": "gcc",
+    "isShellCommand": true,
+    "args": ["-g", "-pthread", "main.c", "-o", "main", "-lm"],
+    "showOutput": "always"
+}

+ 28 - 0
.vscode/tasks.json

@@ -0,0 +1,28 @@
+{
+    "tasks": [
+        {
+            "type": "cppbuild",
+            "label": "C/C++: gcc build active file",
+            "command": "/usr/bin/gcc",
+            "args": [
+                "-fdiagnostics-color=always",
+                "-g",
+                "${file}",
+                "-o",
+                "${fileDirname}/${fileBasenameNoExtension}"
+            ],
+            "options": {
+                "cwd": "${fileDirname}"
+            },
+            "problemMatcher": [
+                "$gcc"
+            ],
+            "group": {
+                "kind": "build",
+                "isDefault": true
+            },
+            "detail": "Task generated by Debugger."
+        }
+    ],
+    "version": "2.0.0"
+}

BIN
main


+ 62 - 0
main.c

@@ -0,0 +1,62 @@
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+
+ 
+
+pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;//создаем и инициализируем мьютекс
+
+ 
+
+int hour = 0;
+int minutes = 0;
+int seconds = 0;
+
+static void* countTime(void *args) {
+    char buffer[100];
+    while (1)
+    {
+        seconds++;
+        if(seconds == 60) {
+            seconds = 0;
+            minutes++;
+        }
+        if (minutes == 60)
+        {
+            minutes = 0;
+            hour++;
+        }
+        if (hour == 24) {
+            hour == 0;
+        }
+        snprintf(buffer,100, "%d:%d:%d", hour, minutes, seconds);
+
+puts(buffer);        
+                        // printf("%d:%d:%d", hour, minutes, seconds);
+                                    sleep(1);
+
+    }        
+
+
+    return NULL;
+}
+
+int main()
+
+{
+    pthread_t main_flow;
+    pthread_create(&main_flow, NULL, countTime, NULL);
+
+    pthread_join(main_flow, NULL);
+
+
+
+    return 0;
+
+}