Feb 29, 2016 at 5:44pm UTC
I'have the following code, but I'need to make 2 file as mur.h and hand.h and call them into here i steads have all code in one file here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
#include "stdafx.h"
# include <iostream>
using namespace System;
using namespace std;
using namespace Threading;
public ref class Eksempel_Stein
{
private : static int ant_steiner;
private : static Semaphore^ stabel_semafor;
private : static Semaphore^ tom_semafor;
private : static Mutex^ skjerm_mutex;
// mur functions
public : static void mur()
{
Random^ rand = gcnew Random;
while (true )
{
stabel_semafor->WaitOne();
ant_steiner--;
skjerm_mutex->WaitOne();
Console::ForegroundColor = ConsoleColor::Green;
cout << "Murer: " << ant_steiner << " er igjen!" << endl;
skjerm_mutex->ReleaseMutex();
stabel_semafor->Release();
if (ant_steiner == 0)
tom_semafor->WaitOne();
int pause = rand->Next(1, 2);
Thread::Sleep(1000 * pause);
}
}
// hand functions
public : static void hand()
{
//Random klasse
Random^ rand = gcnew Random;
while (true )
{
stabel_semafor->WaitOne();
ant_steiner++;
if (ant_steiner == 1)
tom_semafor->Release();
skjerm_mutex->WaitOne();
Console::ForegroundColor = ConsoleColor::Yellow;
cout << "Hand: " << ant_steiner << " er igjen!" << endl;
skjerm_mutex->ReleaseMutex();
stabel_semafor->Release();
int pause = rand->Next(4, 10);
Thread::Sleep(1000 * pause);
}
}
void Main()
{
ant_steiner = 10;
skjerm_mutex = gcnew Mutex();
stabel_semafor = gcnew Semaphore(1, 1);
tom_semafor = gcnew Semaphore(0,1);
skjerm_mutex = gcnew Mutex();
ThreadStart^ threadDelegate1 = gcnew ThreadStart(mur);
ThreadStart^ threadDelegate2 = gcnew ThreadStart(hand);
Thread^ muring = gcnew Thread(threadDelegate1);
muring->Start();
Thread^ hands = gcnew Thread(threadDelegate2);
hands->Start();
}
};
int main()
{
Console::Title = "Program synkronisering" ;
Eksempel_Stein^ eksempel = gcnew Eksempel_Stein();
eksempel->Main();
return 0;
}
Last edited on Feb 29, 2016 at 5:46pm UTC
Feb 29, 2016 at 5:50pm UTC
Using OOP how do I write 3 by 3 matrix that can performed addition, subtraction, multiplication, and find the determinant pls
Feb 29, 2016 at 5:53pm UTC
@aliyu967: Please do not hijack someone else's thread.
Feb 29, 2016 at 5:53pm UTC
@aliyu967 What does your question have to do with the OP? If you have an unrelated question, please start a new thread, rather than trying to confuse someone else's thread.
Feb 29, 2016 at 5:53pm UTC
make 2 file and put theme in a folder and in your main program:
#include "mur.h"
#include "hand.h"
Feb 29, 2016 at 6:02pm UTC
MrTaj, I have already tow file but the problem is which codes should I move from my code example into mur.h