Commits

Dmitry Soldatov committed 719f392

Initial version

Comments (0)

Files changed (7)

Binary file added.

Binary file added.

+#!/bin/bash
+# Local configuration
+QCC=/opt/qnx650/host/linux/x86/usr/bin/qcc
+QNX_INC_DIR=/opt/qnx650/target/qnx6/usr/include
+
+# Remote configuration
+TARGET_MACHINE_IP=172.16.57.129
+TARGET_MACHINE_UNAME=boh
+TARGET_DIR=/home/boh
+
+# Project configuration
+PROJECT_NAME=Lab1
+PROJECT_DIR=/home/boh/qnx_ide-4.7-workspace/Lab2
+SRC_DIR=$PROJECT_DIR/src
+BIN_DIR=$PROJECT_DIR/bin
+OBJ_DIR=$PROJECT_DIR/obj
+
+
+clean_all () {
+    rm $BIN_DIR/* > /dev/null
+    rm $OBJ_DIR/* > /dev/null
+}
+
+compile () {
+    cd $OBJ_DIR;
+    $QCC -Vgcc_ntox86 -c -Wc,-Wall -O -DNDEBUG -I. -I$QNX_INC_DIR \
+    -DVARIANT_x86 -DBUILDENV_qss $SRC_DIR/$1;
+
+    $QCC -Vgcc_ntox86 -o$BIN_DIR/$3 $OBJ_DIR/$2 \
+    -L . \
+    -L /opt/qnx650/target/qnx6/x86/lib \
+    -L /opt/qnx650/target/qnx6/x86/usr/lib \
+    -Wl,--rpath-link . \
+    -Wl,--rpath-link /opt/qnx650/target/qnx6/x86/lib \
+    -Wl,--rpath-link /opt/qnx650/target/qnx6/x86/usr/lib;
+    cd $PROJECT_DIR;
+}
+
+
+clean_all
+compile m1.c m1.o m1
+compile m2.c m2.o m2
+
+ssh $TARGET_MACHINE_UNAME@$TARGET_MACHINE_IP << 'ENDSSH'
+    if [ -d "/home/boh/lab2" ]; then
+        rm /home/boh/lab2/*
+    else
+        mkdir -p /home/boh/lab2
+    fi
+ENDSSH
+
+scp -q $BIN_DIR/* $TARGET_MACHINE_UNAME@$TARGET_MACHINE_IP:/home/boh/lab2/
+
+ssh $TARGET_MACHINE_UNAME@$TARGET_MACHINE_IP 'cd /home/boh/lab2; ./m2'
+

Binary file added.

Binary file added.

+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <pthread.h>
+#include <sync.h>
+#include <semaphore.h>
+#include <fcntl.h>
+
+pthread_barrier_t barrier;
+int lock_flag;
+pthread_t pt1, pt2;
+sem_t* sem;
+
+void f1(char* buf) {
+    pthread_sleepon_lock();
+    pthread_sleepon_wait(&lock_flag);
+    sprintf(strchr(buf, 0), "Thread #1 written down\n");
+    pthread_sleepon_unlock();
+    sem_post(sem);
+    pthread_barrier_wait(&barrier);
+    pthread_join(pt2, NULL);
+    printf("Thread #1 terminated\n");
+    pthread_exit(EXIT_SUCCESS);
+}
+
+void f2(char* buf) {
+    sem_wait(sem);
+    sprintf(strchr(buf, 0), "Thread #2 written down\n");
+    pthread_barrier_wait(&barrier);
+    printf("Thread #2 terminated\n");
+    pthread_exit(EXIT_SUCCESS);
+}
+
+int main(int argc, char *argv[]) {
+    char buf[500];
+    pthread_attr_t attr;
+    pthread_attr_init(&attr);
+    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+    pthread_barrier_init(&barrier, NULL, 3);
+    sem = sem_open("/dev/sem/lab2.sem", O_CREAT, S_IRWXU, 0);
+    pthread_create(&pt1, &attr, (void*)&f1, (void*)&buf);
+    pthread_create(&pt2, &attr, (void*)&f2, (void*)&buf);
+    sprintf(strchr(buf, 0), "Main started\n");
+    pthread_sleepon_lock();
+    pthread_sleepon_signal(&lock_flag);
+    pthread_sleepon_unlock();
+    pthread_barrier_wait(&barrier);
+    printf(buf);
+    //pthread_join(pt1, NULL);
+    printf("Main terminated\n");
+    return EXIT_SUCCESS;
+}
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <pthread.h>
+#include <sync.h>
+#include <semaphore.h>
+#include <fcntl.h>
+
+struct args_struct {
+    void* buf;
+    int tid;
+};
+
+pthread_barrier_t barrier;
+int lock_flag;
+pthread_t pt1, pt2;
+sem_t* sem;
+
+void f(struct args_struct* args) {
+    char* buf = args->buf;
+    int tid = args->tid;
+    switch (tid) {
+        case 1:
+            pthread_sleepon_lock();
+            pthread_sleepon_wait(&lock_flag);
+            sprintf(strchr(buf, 0), "Thread #1 written down\n");
+            pthread_sleepon_unlock();
+            sem_post(sem);
+            pthread_barrier_wait(&barrier);
+            pthread_join(pt2, NULL);
+            printf("Thread #1 terminated\n");
+            pthread_exit(EXIT_SUCCESS);
+            break;
+       case 2:
+            sem_wait(sem);
+            sprintf(strchr(buf, 0), "Thread #2 written down\n");
+            pthread_barrier_wait(&barrier);
+            printf("Thread #2 terminated\n");
+            pthread_exit(EXIT_SUCCESS);
+            break;
+    }
+}
+
+int main(int argc, char *argv[]) {
+    char buf[500];
+    pthread_attr_t attr;
+    pthread_attr_init(&attr);
+    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+    pthread_barrier_init(&barrier, NULL, 3);
+    sem = sem_open("/dev/sem/lab2.sem", O_CREAT, S_IRWXU, 0);
+    struct args_struct args1, args2;
+    args1.buf = &buf;
+    args1.tid = 1;
+    pthread_create(&pt1, &attr, (void*)&f, (void*)&args1);
+    args2.buf = &buf;
+    args2.tid = 2;
+    pthread_create(&pt2, &attr, (void*)&f, (void*)&args2);
+    sprintf(strchr(buf, 0), "Main started\n");
+    pthread_sleepon_lock();
+    pthread_sleepon_signal(&lock_flag);
+    pthread_sleepon_unlock();
+    pthread_barrier_wait(&barrier);
+    printf(buf);
+    //pthread_join(pt1, NULL);
+    printf("Main terminated\n");
+    return EXIT_SUCCESS;
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.