static void Main()
{
// The sum of these elements is 40.
int[] input = { 4, 1, 6, 2, 9, 5, 10, 3 };
int sum = 0;
try
{
Parallel.ForEach(
input, // source collection
() => 0, // thread local initializer
(n, loopState, localSum) => // body
{
localSum += n;
Console.WriteLine("Thread={0}, n={1}, localSum={2}", Thread.CurrentThread.ManagedThreadId, n, localSum);
return localSum;
},
(localSum) => Interlocked.Add(ref sum, localSum) // thread local aggregator
);
Console.WriteLine("nSum={0}", sum);
}
// No exception is expected in this example, but if one is still thrown from a task,
// it will be wrapped in AggregateException and propagated to the main thread.
catch (AggregateException e)
{
Console.WriteLine("Parallel.ForEach has thrown an exception. THIS WAS NOT EXPECTED.n{0}", e);
}
}
같은 코드량으로 c나 자바같은 상대적인 저급 언어보다 할 수 있는 일이 방대할 뿐이지 C#자체를 만만히 보면 안되지
(예를들면 자바에서 데이터를 넣는게 100줄이라면 C#은 넣고 뿌리는게 100줄이면 된다)
저수준에서 구현하는 알고리즘(시멘트 제조)은 다 구현해놓았으니 개발자는 그런거 신경쓰지 말고 건물 설계와 건축만 하라는게 닷넷의 가치관이지
근데 C#은 일거리가 없음.. 배우진 마라...
{
// The sum of these elements is 40.
int[] input = { 4, 1, 6, 2, 9, 5, 10, 3 };
int sum = 0;
try
{
Parallel.ForEach(
input, // source collection
() => 0, // thread local initializer
(n, loopState, localSum) => // body
{
localSum += n;
Console.WriteLine("Thread={0}, n={1}, localSum={2}", Thread.CurrentThread.ManagedThreadId, n, localSum);
return localSum;
},
(localSum) => Interlocked.Add(ref sum, localSum) // thread local aggregator
);
Console.WriteLine("nSum={0}", sum);
}
// No exception is expected in this example, but if one is still thrown from a task,
// it will be wrapped in AggregateException and propagated to the main thread.
catch (AggregateException e)
{
Console.WriteLine("Parallel.ForEach has thrown an exception. THIS WAS NOT EXPECTED.n{0}", e);
}
}
같은 코드량으로 c나 자바같은 상대적인 저급 언어보다 할 수 있는 일이 방대할 뿐이지 C#자체를 만만히 보면 안되지
(예를들면 자바에서 데이터를 넣는게 100줄이라면 C#은 넣고 뿌리는게 100줄이면 된다)
저수준에서 구현하는 알고리즘(시멘트 제조)은 다 구현해놓았으니 개발자는 그런거 신경쓰지 말고 건물 설계와 건축만 하라는게 닷넷의 가치관이지
근데 C#은 일거리가 없음.. 배우진 마라...
뭐라는거야... 밥은 먹고 다니냐?
언어의 능력은 컴파일러의 성능과도 관계가 있다. c#이 c언어같이 인라인 어셈블리도 컴파일할 수 있으면 지존급이 되는거지
c#의 태생적인 한계로 인라인 어셈은 좀 무리일지도 ㅎㅎ
아 c#인라인 어셈 된다네요 지존이네 ㅋㅋ
닷넷은 컴파일러 최적화같은 연산 루프 하나 덜 도는 식으로 속도 향상을 꾀하진 않고 병렬 처리로 딜레이를 없애지. 본문 예제도 단 5줄에 멀티 스레드와 동기화를 하는거임
C#의 인라인 어셈은 어셈블리 언어의 어셈을 의미하는건 아니고 클래스나 함수 등 모든걸 런타임에 생성해서 실행할 수 있다는거... 그러니까 프로그램이 실행하면 코드 자체가 코드를 짜서 인스턴스를 만들고 그 인스턴스를 실행함..