Updates to Semaphor
This commit is contained in:
13
P5/Main.cpp
13
P5/Main.cpp
@@ -9,6 +9,7 @@ using namespace std;
|
||||
// Thread T1 - Schreibt alle Kleinbuchstaben des Alphabets
|
||||
void thread1()
|
||||
{
|
||||
cout << "T1: ";
|
||||
for (char c = 'a'; c <= 'z'; ++c)
|
||||
{
|
||||
cout << c << ' ';
|
||||
@@ -19,6 +20,7 @@ void thread1()
|
||||
// Thread T2 - Schreibt alle natürlichen Zahlen von 0 bis 32
|
||||
void thread2()
|
||||
{
|
||||
cout << "T2: ";
|
||||
for (int i = 0; i <= 32; ++i)
|
||||
{
|
||||
cout << i << ' ';
|
||||
@@ -29,6 +31,7 @@ void thread2()
|
||||
// Thread T3 - Schreibt alle Großbuchstaben des Alphabets
|
||||
void thread3()
|
||||
{
|
||||
cout << "T3: ";
|
||||
for (char c = 'A'; c <= 'Z'; ++c)
|
||||
{
|
||||
cout << c << ' ';
|
||||
@@ -54,7 +57,7 @@ mutex mtx;
|
||||
void mutexThread1()
|
||||
{
|
||||
mtx.lock();
|
||||
|
||||
cout << "T1: ";
|
||||
for (char ch = 'a'; ch <= 'z'; ch++)
|
||||
{
|
||||
cout << ch << " ";
|
||||
@@ -68,7 +71,7 @@ void mutexThread2()
|
||||
{
|
||||
|
||||
mtx.lock();
|
||||
|
||||
cout << "T2: ";
|
||||
for (int i = 0; i < 33; i++)
|
||||
{
|
||||
cout << i << " ";
|
||||
@@ -81,7 +84,7 @@ void mutexThread2()
|
||||
void mutexThread3()
|
||||
{
|
||||
mtx.lock();
|
||||
|
||||
cout << "T3: ";
|
||||
for (char ch = 'A'; ch <= 'Z'; ch++)
|
||||
{
|
||||
cout << ch << " ";
|
||||
@@ -106,6 +109,7 @@ Semaphor semaphor(1);
|
||||
void semaphoreThread1()
|
||||
{
|
||||
semaphor.acquire();
|
||||
cout << "T1: ";
|
||||
for (char ch = 'a'; ch <= 'z'; ch++)
|
||||
{
|
||||
cout << ch << " ";
|
||||
@@ -117,6 +121,7 @@ void semaphoreThread1()
|
||||
void semaphoreThread2()
|
||||
{
|
||||
semaphor.acquire();
|
||||
cout << "T2: ";
|
||||
for (int i = 0; i < 33; i++)
|
||||
{
|
||||
cout << i << " ";
|
||||
@@ -128,6 +133,7 @@ void semaphoreThread2()
|
||||
void semaphoreThread3()
|
||||
{
|
||||
semaphor.acquire();
|
||||
cout << "T3: ";
|
||||
for (char ch = 'A'; ch <= 'Z'; ch++)
|
||||
{
|
||||
cout << ch << " ";
|
||||
@@ -148,7 +154,6 @@ void semaphore_init()
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
cout << "Asynch" << endl;
|
||||
asynch_init();
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ private:
|
||||
int count;
|
||||
std::mutex mtx;
|
||||
std::condition_variable cond;
|
||||
std::queue<std::thread::id> wait_queue; // Beispielhafte Warteschlange
|
||||
|
||||
public:
|
||||
Semaphor(int i) : count(i) {}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user