락스텝이 걸리는 데커 알고리즘 1
락스텝 = 1개의 프로세서가 실행되면 다른 1개의 프로세서도 반드시 실행되어야 된다. 번갈아 가면서
forC#
Trackback url :: http://hahakbs.dothost.co.kr/trackback/22

락스텝이 걸리는 데커 알고리즘 1
락스텝 = 1개의 프로세서가 실행되면 다른 1개의 프로세서도 반드시 실행되어야 된다. 번갈아 가면서
forC#
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace Dekker1
{
class Program
{
public int ProcessNumber;
public void Processor1()
{
while (true)
{
while (ProcessNumber == 2) ;
lock(this)
{
ProcessNumber = 2;
Console.WriteLine("프로세스 값 변경 : 2");
}
}
}
public void Processor2()
{
while (true)
{
while (ProcessNumber == 1) ;
lock (this)
{
ProcessNumber = 1;
Console.WriteLine("프로세스 값 변경 : 1");
}
}
}
static void Main(string[] args)
{
Console.WriteLine("테스트");
Program pr = new Program();
Thread th1 = new Thread(new ThreadStart(pr.Processor1));
Thread th2 = new Thread(new ThreadStart(pr.Processor2));
pr.ProcessNumber = 1;
th1.Start();
th2.Start();
}
}
}
// 락스텝이 걸려버린다.
// 락스텝이란 1개의 프로세스가 한번 수행 되면 다른 프로세스가 반드시 수행되어야 실행될수 있다.


| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 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 |
댓글을 달아 주세요