Click here to Skip to main content
15,911,503 members
Home / Discussions / C#
   

C#

 
AnswerRe: MultiThreading, went back to basics.. Pin
Rob Philpott26-Nov-08 8:08
Rob Philpott26-Nov-08 8:08 
GeneralRe: MultiThreading, went back to basics.. Pin
EliottA26-Nov-08 8:23
EliottA26-Nov-08 8:23 
GeneralRe: MultiThreading, went back to basics.. Pin
Dan Neely26-Nov-08 8:49
Dan Neely26-Nov-08 8:49 
GeneralRe: MultiThreading, went back to basics.. Pin
EliottA26-Nov-08 8:28
EliottA26-Nov-08 8:28 
QuestionRe: MultiThreading, went back to basics.. Pin
led mike26-Nov-08 8:33
led mike26-Nov-08 8:33 
AnswerRe: MultiThreading, went back to basics.. Pin
EliottA26-Nov-08 8:35
EliottA26-Nov-08 8:35 
AnswerRe: MultiThreading, went back to basics.. Pin
Dan Neely26-Nov-08 8:47
Dan Neely26-Nov-08 8:47 
AnswerRe: MultiThreading, went back to basics.. Pin
Luc Pattyn26-Nov-08 10:02
sitebuilderLuc Pattyn26-Nov-08 10:02 
Hi,

on a single core without hyperthreading the CPU will be used by one thread until it runs out of a job, or something really significant occurs that makes the OS decide to switch threads; threads are not switching all the time, it is just too expensive.

You could add a random delay (with Thread.Sleep) to one or both of your threads; and then you could set one of them at a "below normal" priority, to make things more interesting (make sure the highest priority one has reasons not to finish in one stint).

As soon as hyperthreading or multi-core hardware is involved, two or more threads may really run at the same time, until or unless they get synchronized somehow. Both of them using the same TextWriter will synchronize them: the class has to do something to prevent characters of multiple lines (from different threads) getting intertwined.

Another experiment would be:
have one integer counter as class members.
thread1 increments counter and stores value of counter in a List<int>
thread2 decrements counter and stores value of counter in another List<int>
Don't call any I/O in those threads, don't create a possible synchronization point, just let them try to get 100% of the CPU cycles.
After some time, stop both threads and list (part of) one or both Lists.

Without multicore/HT the lists will be monotonous for a long time (say 16 msec); with MC/HT they ideally would oscillate around zero assuming identical code in both threads, and they would evolve "slowly" if one of the threads wastes some cycles with respect to the other (by adding some statements that don't get optimized away).

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

Fixturized forever. Confused | :confused:


GeneralRe: MultiThreading, went back to basics.. Pin
EliottA26-Nov-08 10:10
EliottA26-Nov-08 10:10 
GeneralRe: MultiThreading, went back to basics.. Pin
Luc Pattyn26-Nov-08 10:38
sitebuilderLuc Pattyn26-Nov-08 10:38 
AnswerRe: MultiThreading, went back to basics.. Pin
jas0n2326-Nov-08 18:07
jas0n2326-Nov-08 18:07 
QuestionVMR9 issue [modified] Pin
GrizzlyDoug26-Nov-08 7:09
GrizzlyDoug26-Nov-08 7:09 
AnswerRe: VMR9 issue Pin
MBrooker7-Mar-09 6:23
MBrooker7-Mar-09 6:23 
QuestionTry...Catch block Pin
EliottA26-Nov-08 6:54
EliottA26-Nov-08 6:54 
AnswerRe: Try...Catch block Pin
PIEBALDconsult26-Nov-08 7:29
mvePIEBALDconsult26-Nov-08 7:29 
AnswerRe: Try...Catch block Pin
Gideon Engelberth26-Nov-08 7:33
Gideon Engelberth26-Nov-08 7:33 
AnswerRe: Try...Catch block Pin
Paul Conrad26-Nov-08 9:23
professionalPaul Conrad26-Nov-08 9:23 
GeneralRe: Try...Catch block [modified] Pin
Luc Pattyn26-Nov-08 10:31
sitebuilderLuc Pattyn26-Nov-08 10:31 
QuestionSearching for URL's in... Pin
jas0n2326-Nov-08 6:19
jas0n2326-Nov-08 6:19 
AnswerRe: Searching for URL's in... Pin
Christian Graus26-Nov-08 7:44
protectorChristian Graus26-Nov-08 7:44 
QuestionRe: Searching for URL's in... Pin
jas0n2326-Nov-08 16:32
jas0n2326-Nov-08 16:32 
QuestionLinq - Inserting into IDENTITY column. Pin
Exception Duck26-Nov-08 5:52
Exception Duck26-Nov-08 5:52 
QuestionHTTPContext for Remote object. (i didn't find Remoting forum) Pin
Member 232448326-Nov-08 5:47
Member 232448326-Nov-08 5:47 
QuestionConfigurationSettings Pin
madhu.nzd26-Nov-08 4:21
madhu.nzd26-Nov-08 4:21 
QuestionAssertions Pin
CodingYoshi26-Nov-08 4:05
CodingYoshi26-Nov-08 4:05 

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.