본문 바로가기

[2-3]operating system/[2-3.2]Thread6

[Thread Book #4 ] 스레드 중단 [Thread Book #4 ] 스레드 중단 다른 스레드 실행을 중단하는 방법이다. class Program { static void Main(string[] args) { Console.WriteLine("Starting program..."); Thread t = new Thread(PrintNumbersWithDelay); t.Start(); Thread.Sleep(TimeSpan.FromSeconds(6)); t.Abort(); Console.WriteLine("A thread has been aborted"); } static void PrintNumbersWithDelay() { Console.WriteLine("Starting..."); for (int i = 1; i < 10; i++) {.. 2020. 6. 13.
스레드 동기화 한 스레드가 증감 연산을 수행할 때, 다른 스레드는 끝날 때까지 기다려야 한다. 이런 일반적인 문제는 흔히 '스레드 동기화' 라고 한다. 스레드 동기화를 달성하는 여러가지 방법이 있다. 먼저 공유 객체가 없으면 전형 동기화할 필요가 없다. 놀랍게도 프로그램을 재설계하고 공유 상태를 제거함으로써 복잡한 동기화 생성자를 자주 없앨수 있다. 이것이 가능하다면 여러 스레드가 단일 객체를 사용하는 것을 피하면 된다. 공유 상태가 꼭 필요한 경우 두번째 방식은 원자 연산 atomic poeration 만 사용하는 것인데, 연산이 단일 시간량 quantum of time 을 받아 즉시 완료함을 의미한다. 따라서 첫 번째 연산이 완료될 때까지 다른 연산을 수행할 수 있는 스레드가 존재하지 않는다. 그런 이유로 연산이 .. 2020. 6. 13.
[Thread Book #5] 스레드 상태 조사 [Thread Book #5] 스레드 상태 조사 스레드가 가질 수 있는 상태를 설명하며 스레드가 이제 시작됐는지의 여부나 스레드가 봉쇄 상태인지의 여부에 관한 정보를 얻을때 유용하다. 스레드는 독립적으로 실행되므로 언제든지 상태가 바뀔수 있음에 주목하길 바란다. class Program { static void Main(string[] args) { Console.WriteLine("Starting program..."); Thread t = new Thread(PrintNumbersWithStatus); Thread t2 = new Thread(DoNothing); Console.WriteLine(t.ThreadState.ToString()); t2.Start(); t.Start(); for (int .. 2020. 6. 12.
스레드의 파라미터 전달 class Program { static void Main(string[] args) { var sample = new ThreadSample(10); var threadOne = new Thread(sample.CountNumbers); threadOne.Name = "ThreadOne"; threadOne.Start(); threadOne.Join(); Console.WriteLine("--------------------------"); var threadTwo = new Thread(Count); threadTwo.Name = "ThreadTwo"; threadTwo.Start(8); threadTwo.Join(); Console.WriteLine("--------------------------.. 2020. 5. 13.
스레드 우선순위 스레드 우선순위 스레드 우선순위에 대한 다른 가능한 옵션을 설명하며,또한 스레드에 CPU 시간을 어떻게 할당할지 결정하는 스레드 우선 순위를 설정하는 방법을 제시한다. class Program { static void Main(string[] args) { // 다른 두 스레드를 정의한 메인 프로그램을 시작한다. //메인 스레드 우선순위 값을 출력한후,활용가능 한 모든 코어에서 두 스레드를 실행한다. //연산 코어가 하나 이상이 있다면, 2초 안에 첫 결과를 얻는다. //가장 높은 우선순위인 스레드는 보통 더 반복해서 계산 해야한다. //다만, 두값이 서로 가까워야 한다. 하지만 어떤 다른 프로그램이 //모든 CPU 코어를 적재해 실행하고 있을 때는 상황이 상당히 달라질수 있다. Console.Write.. 2020. 5. 6.
Using WaitingBar with a Background Worker | UI for WinForms Documentation | Telerik UI for WinForms Using WaitingBar with a Background Worker RadWaitingBar is a useful control for indicating that a long-running operation is undergoing. When using this control, however, many users face a similar issue: once the time-consuming operation is started, the control does not move its indicators and literally freezes. Such cases occur when the long-running operation is executed on the same thread as th.. 2020. 2. 18.