Click here to Skip to main content
15,562,222 members
Home / Discussions / C#
   

C#

 
QuestionAnother Question. Pin
travich7-Jan-07 8:51
travich7-Jan-07 8:51 
GeneralRe: Another Question. Pin
Guffa7-Jan-07 10:54
Guffa7-Jan-07 10:54 
QuestionCookie-less Authentication Pin
Rahithi6-Jan-07 18:42
Rahithi6-Jan-07 18:42 
AnswerRe: Cookie-less Authentication Pin
Christian Graus6-Jan-07 21:04
mveChristian Graus6-Jan-07 21:04 
QuestionIssues with RemoveChild() Pin
csharpk0der1236-Jan-07 18:23
csharpk0der1236-Jan-07 18:23 
AnswerRe: Issues with RemoveChild() Pin
Christian Graus6-Jan-07 21:07
mveChristian Graus6-Jan-07 21:07 
AnswerRe: Issues with RemoveChild() Pin
Luc Pattyn7-Jan-07 10:15
sitebuilderLuc Pattyn7-Jan-07 10:15 
QuestionI cant seem to think today. Pin
Captain See Sharp6-Jan-07 17:56
Captain See Sharp6-Jan-07 17: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 19:18
sitebuilderLuc Pattyn6-Jan-07 19:18 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp6-Jan-07 19:43
Captain See Sharp6-Jan-07 19:43 
GeneralRe: I cant seem to think today. Pin
Luc Pattyn6-Jan-07 20:02
sitebuilderLuc Pattyn6-Jan-07 20:02 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp6-Jan-07 20:34
Captain See Sharp6-Jan-07 20:34 
GeneralRe: I cant seem to think today. Pin
Luc Pattyn6-Jan-07 21:04
sitebuilderLuc Pattyn6-Jan-07 21:04 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp6-Jan-07 21:23
Captain See Sharp6-Jan-07 21:23 
GeneralRe: I cant seem to think today. Pin
Luc Pattyn6-Jan-07 21:27
sitebuilderLuc Pattyn6-Jan-07 21:27 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp6-Jan-07 21:32
Captain See Sharp6-Jan-07 21:32 
GeneralRe: I cant seem to think today. Pin
Luc Pattyn6-Jan-07 21:53
sitebuilderLuc Pattyn6-Jan-07 21:53 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp6-Jan-07 22:04
Captain See Sharp6-Jan-07 22:04 
GeneralRe: I cant seem to think today. Pin
Luc Pattyn7-Jan-07 8:20
sitebuilderLuc Pattyn7-Jan-07 8:20 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp7-Jan-07 8:25
Captain See Sharp7-Jan-07 8:25 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp7-Jan-07 8:34
Captain See Sharp7-Jan-07 8:34 
GeneralRe: I cant seem to think today. Pin
Luc Pattyn7-Jan-07 8:43
sitebuilderLuc Pattyn7-Jan-07 8:43 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp7-Jan-07 8:59
Captain See Sharp7-Jan-07 8:59 
GeneralRe: I cant seem to think today. Pin
Luc Pattyn7-Jan-07 9:51
sitebuilderLuc Pattyn7-Jan-07 9:51 
GeneralRe: I cant seem to think today. Pin
Captain See Sharp7-Jan-07 10:29
Captain See Sharp7-Jan-07 10: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.