MUP1+Øvelse+6.1

toc =Basic OS API use=

Sender
code format="cpp" // Header
 * 1) pragma once
 * 2) include

class Sender : public Thread { public: Sender(Mailbox *); void run; ~Sender(void); private: Mailbox *mb; };

// Source include "Sender.h"

Sender::Sender(Mailbox * mb) {	this->mb=mb; } void Sender::run {	while(true) {		mb->put("Din Far"); } }

Sender::~Sender(void) { } code

Receiver
code format="cpp" // Header class Receiver : public Thread { public: Receiver(Mailbox *); void run; ~Receiver(void); private: Mailbox *mb; };
 * 1) pragma once
 * 2) include "win32wrap.h"

// Source
 * 1) include "Receiver.h"
 * 2) include

using namespace std;

Receiver::Receiver(Mailbox * mb) {	this->mb=mb; }

void Receiver::run {	while(true) {		cout << mb->get << endl; } }

Receiver::~Receiver(void) { }

code

Main
code format="cpp"
 * 1) include "Receiver.h"
 * 2) include "Sender.h"

using namespace std;

int main {	Mailbox mb(10); Receiver t_rec(&mb); Sender t_sen(&mb); SleepTimer t;

t_rec.start; t_sen.start;

while(true) {		t.sleep(1000); }

return 0; } code