Click here to Skip to main content
15,900,666 members
Home / Discussions / C#
   

C#

 
AnswerRe: COM Port Settings Pin
Mostafa Siraj7-Jan-07 8:50
Mostafa Siraj7-Jan-07 8:50 
QuestionMay be a stupid question... Pin
hprahul7-Jan-07 4:39
hprahul7-Jan-07 4:39 
AnswerRe: May be a stupid question... Pin
Rob Graham7-Jan-07 6:05
Rob Graham7-Jan-07 6:05 
QuestionUnable to read black and white image Pin
code_explorer7-Jan-07 4:39
code_explorer7-Jan-07 4:39 
AnswerRe: Unable to read black and white image Pin
rizgar8-Jan-07 19:12
rizgar8-Jan-07 19:12 
QuestionEsc Key pressed Event Pin
swjam7-Jan-07 3:21
swjam7-Jan-07 3:21 
AnswerRe: Esc Key pressed Event Pin
Guffa7-Jan-07 3:33
Guffa7-Jan-07 3:33 
AnswerRe: Esc Key pressed Event Pin
Luc Pattyn7-Jan-07 7:54
sitebuilderLuc Pattyn7-Jan-07 7:54 
QuestionImage quality Pin
Mazdak7-Jan-07 2:15
Mazdak7-Jan-07 2:15 
AnswerRe: Image quality Pin
Nader Elshehabi7-Jan-07 2:43
Nader Elshehabi7-Jan-07 2:43 
GeneralRe: Image quality Pin
Mazdak7-Jan-07 3:42
Mazdak7-Jan-07 3:42 
AnswerRe: Image quality Pin
J. Dunlap7-Jan-07 3:16
J. Dunlap7-Jan-07 3:16 
GeneralRe: Image quality Pin
Mazdak7-Jan-07 3:41
Mazdak7-Jan-07 3:41 
AnswerRe: Image quality Pin
Guffa7-Jan-07 3:49
Guffa7-Jan-07 3:49 
QuestionQuestion about Page_Load event... Pin
travich6-Jan-07 20:14
travich6-Jan-07 20:14 
AnswerRe: Question about Page_Load event... Pin
Guffa7-Jan-07 4:16
Guffa7-Jan-07 4:16 
QuestionAnother Question. Pin
travich7-Jan-07 7:51
travich7-Jan-07 7:51 
GeneralRe: Another Question. Pin
Guffa7-Jan-07 9:54
Guffa7-Jan-07 9:54 
QuestionCookie-less Authentication Pin
Rahithi6-Jan-07 17:42
Rahithi6-Jan-07 17:42 
AnswerRe: Cookie-less Authentication Pin
Christian Graus6-Jan-07 20:04
protectorChristian Graus6-Jan-07 20:04 
QuestionIssues with RemoveChild() Pin
csharpk0der1236-Jan-07 17:23
csharpk0der1236-Jan-07 17:23 
AnswerRe: Issues with RemoveChild() Pin
Christian Graus6-Jan-07 20:07
protectorChristian Graus6-Jan-07 20:07 
AnswerRe: Issues with RemoveChild() Pin
Luc Pattyn7-Jan-07 9:15
sitebuilderLuc Pattyn7-Jan-07 9:15 
QuestionI cant seem to think today. Pin
Captain See Sharp6-Jan-07 16:56
Captain See Sharp6-Jan-07 16:56 
I have a function that will divide a loop iteration among threads. Each thread will be given its portion of work to do by giving it the array to iterate through and the start and end index that will be the range of indexes it will work on. I'm also assuming that I will not need to synchronize the access to the array since it works on each variable independently but I may be wrong. Here is what I have.
//i know this is not complete but all i need is to figure out how to divide the indexes up
public Range[] ReturnIndexRanges(long[] indexes)
{
  Range[] ranges = null;
  Thread[] threads = new Thread[Environment.ProcessorCount];
  long length = ((end - start) + 1) / Environment.ProcessorCount;

  _start = start;

  foreach (Thread t in threads)
  {
    t = new Thread(new ParameterizedThreadStart(ReturnRangesOfIndexes));
    t.Start(new ThreadedReturnRangesOfIndexData(ranges, indexes, _start, length - 1));
    _start += length;
    length = end - length + 1;
  }
  //each thread will have its own range array when this is finished.
  return JoinDividedRanges(ranges);
}


private class ThreadedReturnRangesOfIndexData
{
  public ThreadedReturnRangesOfIndexData(Range[] ranges, long[] indexes, long start, long end)
  {
    ranges_out = ranges;
    indexes_in = indexes;
    this.start = start;
    this.end = end;
  }
  public long start, end;
  public long[] indexes_in;
  public Range[] ranges_out;
}


The ThreadedReturnRangesOfIndexData class is just a small class that hold some information such as the array of the indexes being passed into the method and the array of Ranges that will be returned. It will be like ref but since it is an array I do not need to add ref or out to it because an array is a reference type.

What I need is to figure out how to divide the indexes up evenly in the ReturnIndexRanges method at the top. This is my first attempt at creating a multi-threaded program so I would appreciate some tips if you have any. Should I just forget about threading?




█▒▒▒▒▒██▒█▒██
█▒█████▒▒▒▒▒█
█▒██████▒█▒██
█▒█████▒▒▒▒▒█
█▒▒▒▒▒██▒█▒██

AnswerRe: I cant seem to think today. Pin
Luc Pattyn6-Jan-07 18:18
sitebuilderLuc Pattyn6-Jan-07 18:18 

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.