Click here to Skip to main content
15,891,316 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp6-Jan-07 18:43
Captain See Sharp6-Jan-07 18:43 
GeneralRe: I cant seem to think today. Pin
Luc Pattyn6-Jan-07 19:02
sitebuilderLuc Pattyn6-Jan-07 19:02 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp6-Jan-07 19:34
Captain See Sharp6-Jan-07 19:34 
GeneralRe: I cant seem to think today. Pin
Luc Pattyn6-Jan-07 20:04
sitebuilderLuc Pattyn6-Jan-07 20:04 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp6-Jan-07 20:23
Captain See Sharp6-Jan-07 20:23 
GeneralRe: I cant seem to think today. Pin
Luc Pattyn6-Jan-07 20:27
sitebuilderLuc Pattyn6-Jan-07 20:27 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp6-Jan-07 20:32
Captain See Sharp6-Jan-07 20:32 
GeneralRe: I cant seem to think today. Pin
Luc Pattyn6-Jan-07 20:53
sitebuilderLuc Pattyn6-Jan-07 20:53 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp6-Jan-07 21:04
Captain See Sharp6-Jan-07 21:04 
GeneralRe: I cant seem to think today. Pin
Luc Pattyn7-Jan-07 7:20
sitebuilderLuc Pattyn7-Jan-07 7:20 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp7-Jan-07 7:25
Captain See Sharp7-Jan-07 7:25 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp7-Jan-07 7:34
Captain See Sharp7-Jan-07 7:34 
GeneralRe: I cant seem to think today. Pin
Luc Pattyn7-Jan-07 7:43
sitebuilderLuc Pattyn7-Jan-07 7:43 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp7-Jan-07 7:59
Captain See Sharp7-Jan-07 7:59 
GeneralRe: I cant seem to think today. Pin
Luc Pattyn7-Jan-07 8:51
sitebuilderLuc Pattyn7-Jan-07 8:51 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp7-Jan-07 9:29
Captain See Sharp7-Jan-07 9:29 

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.