Click here to Skip to main content
15,913,610 members
Home / Discussions / C#
   

C#

 
GeneralKeyboard language Pin
ABBASI_RA20-Mar-05 16:03
ABBASI_RA20-Mar-05 16:03 
GeneralRe: Keyboard language Pin
Christian Graus20-Mar-05 16:27
protectorChristian Graus20-Mar-05 16:27 
GeneralRe: Keyboard language Pin
Dave Kreskowiak20-Mar-05 17:27
mveDave Kreskowiak20-Mar-05 17:27 
Generalopen window Pin
ABBASI_RA20-Mar-05 15:46
ABBASI_RA20-Mar-05 15:46 
GeneralRe: open window Pin
Dave Kreskowiak20-Mar-05 17:28
mveDave Kreskowiak20-Mar-05 17:28 
GeneralRe: open window Pin
ABBASI_RA20-Mar-05 17:38
ABBASI_RA20-Mar-05 17:38 
GeneralRe: open window Pin
Dave Kreskowiak24-Mar-05 1:40
mveDave Kreskowiak24-Mar-05 1:40 
GeneralMultithreading on dual machine problem Pin
omid_dt20-Mar-05 10:38
omid_dt20-Mar-05 10:38 
Hi all,

In my code I have a bottleneck which consists of a cpu-intensive loop of
size LENGTH. What I did was to divide that loop into two threads, Thread1
doing the 0 to LENGTH/2 part, and Thread2 doing the LENGTH/2 to LENGTH part.
There is no synchronization between threads, so they should work pretty
freely.

My machine has two processors (dual P3, Windows 2003 server). Now comes the
problem: when running the program, both threads are scheduled on the *same*
processor! I checked many things, for example:

1) Added a while(true); infinite loop, and it resulted in each thread be
scheduled to another processor (this was a test of course, I don't need an
infinite loop!).

2) Added the following code the loops in each thread:
for (int i = 0; l < 10000000; i++);
Just an empty loop that wastes CPU. Strangely enough, this somehow signals
to the scheduler that the threads are cpu-intensive and so each thread is
scheduled on different processor.

I would like to mention again that even without this wasteful loop each
thread is already 100% cpu-intensive, and so it is very strange that the
scheduler does not assign each thread to seperate processor.

As a last resort, I tried using a Win API call to SetThreadAffinityMask to
manually assign each thread to seperate processor. This to no avail, as my
request was ignored! (although the SetThreadAffinityMask function did not
return a fail status.) Again, strangely enough, when I use
SetThreadAffinityMask in the while(true) example above to ask the scheduler
to assign both threads to same processor, the scheduler does respect the
request and assigns both threads to same processor.

Finally, I have to mention that within the loops many memory accesses are
done (though no memory allocations). Is it possible that because of this the
scheduler places both threads on same processor to share L1 cache? (Though
after many years of parallel programming in C/C++ I have never encountered
such a strange behavior).

And if not, is it possible that the problem is because of a bug in .NET
Framework thread handling?

Thanks in advance for any reply that might shed some light on this mystery.
GeneralRe: Multithreading on dual machine problem Pin
Rei Miyasaka21-Mar-05 0:13
Rei Miyasaka21-Mar-05 0:13 
GeneralRe: Multithreading on dual machine problem Pin
omid_dt21-Mar-05 1:25
omid_dt21-Mar-05 1:25 
GeneralRe: Multithreading on dual machine problem Pin
Rei Miyasaka21-Mar-05 1:48
Rei Miyasaka21-Mar-05 1:48 
GeneralRe: Multithreading on dual machine problem Pin
Judah Gabriel Himango21-Mar-05 6:28
sponsorJudah Gabriel Himango21-Mar-05 6:28 
GeneralFinding out number of methods subscribed to an event Pin
Flack20-Mar-05 10:14
Flack20-Mar-05 10:14 
GeneralRe: Finding out number of methods subscribed to an event Pin
MoustafaS20-Mar-05 10:54
MoustafaS20-Mar-05 10:54 
GeneralRe: Finding out number of methods subscribed to an event Pin
Flack20-Mar-05 17:11
Flack20-Mar-05 17:11 
GeneralRe: Finding out number of methods subscribed to an event Pin
leppie20-Mar-05 21:44
leppie20-Mar-05 21:44 
QuestionHow To: Get the current method that a thread is executing? Pin
Tristan Rhodes20-Mar-05 9:32
Tristan Rhodes20-Mar-05 9:32 
AnswerRe: How To: Get the current method that a thread is executing? Pin
Robert Rohde20-Mar-05 10:09
Robert Rohde20-Mar-05 10:09 
GeneralRe: How To: Get the current method that a thread is executing? Pin
Tristan Rhodes20-Mar-05 11:02
Tristan Rhodes20-Mar-05 11:02 
GeneralAccess Windows process in C# Pin
Nir Doron20-Mar-05 4:12
sussNir Doron20-Mar-05 4:12 
GeneralRe: Access Windows process in C# Pin
Magnus2720-Mar-05 8:09
Magnus2720-Mar-05 8:09 
GeneralCan&#8217;t save a bitmap to MemoryStream as GIF Pin
Magnus2720-Mar-05 3:57
Magnus2720-Mar-05 3:57 
GeneralRe: Can&#8217;t save a bitmap to MemoryStream as GIF Pin
WillemM20-Mar-05 6:24
WillemM20-Mar-05 6:24 
GeneralRe: Can&#8217;t save a bitmap to MemoryStream as GIF Pin
Magnus2720-Mar-05 8:04
Magnus2720-Mar-05 8:04 
GeneralRe: Can&#8217;t save a bitmap to MemoryStream as GIF Pin
leppie20-Mar-05 9:06
leppie20-Mar-05 9:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.