Click here to Skip to main content
15,887,585 members
Home / Discussions / C#
   

C#

 
GeneralRe: Delegate casting/conversion Pin
harold aptroot21-Aug-10 5:42
harold aptroot21-Aug-10 5:42 
GeneralRe: Delegate casting/conversion Pin
DaveyM6921-Aug-10 5:59
professionalDaveyM6921-Aug-10 5:59 
GeneralRe: Delegate casting/conversion Pin
harold aptroot21-Aug-10 6:24
harold aptroot21-Aug-10 6:24 
GeneralRe: Delegate casting/conversion Pin
DaveyM6921-Aug-10 6:28
professionalDaveyM6921-Aug-10 6:28 
GeneralRe: Delegate casting/conversion Pin
harold aptroot21-Aug-10 6:33
harold aptroot21-Aug-10 6:33 
GeneralRe: Delegate casting/conversion Pin
DaveyM6921-Aug-10 6:40
professionalDaveyM6921-Aug-10 6:40 
GeneralRe: Delegate casting/conversion Pin
harold aptroot21-Aug-10 6:45
harold aptroot21-Aug-10 6:45 
QuestionThreading for multicore applications Pin
Steven Solberg21-Aug-10 5:20
Steven Solberg21-Aug-10 5:20 
Hi Guys

I was working on a new class to simplify my code for multicore apps, but I stumbled on some difficulties...
I have already written code to exploit a dualcore and a quadcore, but only i a static fashion.
What I would like the class to do is, accept a method by means of a delegate and some arguments.
Then the class should check the number of cores and start the same number of threads, each with the subset of the arguments.
Let me clarify this... Suppose I have 20 images and I want to make all of them grayscale. I could assign every core a diiferent set of images to work on, since these operations do not interfere with eachother. As I said, I have already made a similar thing for dualcore, but I want to let the class sort this out by itself, so that in theory even a 99-core is supported.
The difficulties I'm having are more concerned with the delegates and arguments that need passing. This is what I have at the moment. Consider this pseudo-code because I think it's filled with errors Hmmm | :|
private static List<Thread> threads = new List<Thread> (0);
private static List<ThreadMethod> methods = new List<ThreadMethod>(0);

public delegate void xCO_Method(); delegate void CallBack(Thread T);
static private xCO_Method Method; static private CallBack CallBackMethod;

public static void Start(xCO_Method method, object[] args)
{
    int cpu = System.Environment.ProcessorCount;
    Method = method;
    CallBackMethod = new CallBack(Completed);

    for (int i = 0; i < cpu; i++)
    {
        methods.Add(new ThreadMethod());
        threads.Add(new Thread(methods[i].Work));
        threads[i].Name = i.ToString();
    }

    foreach (Thread T in threads)
        T.Start(args[i]);
}

private class ThreadMethod
{
    public object[] Result;
    public void Work()
    { 
        //Do Work
        Method.Invoke(args);
    
        //CallBack
        CallBackMethod.Invoke(Thread.CurrentThread);
    }
}

private static void Completed(Thread T)
{
    Console.WriteLine("Thread " + T.Name + " ended");
}


Basically I want to prevent having to write a bunch of overloads and delegates for all kinds of methods.
But perhaps there is a better way.

Thanks
GeneralRe: Threading for multicore applications Pin
harold aptroot21-Aug-10 5:44
harold aptroot21-Aug-10 5:44 
GeneralRe: Threading for multicore applications [modified] Pin
Steven Solberg21-Aug-10 6:13
Steven Solberg21-Aug-10 6:13 
GeneralRe: Threading for multicore applications Pin
harold aptroot21-Aug-10 6:42
harold aptroot21-Aug-10 6:42 
GeneralRe: Threading for multicore applications Pin
Steven Solberg21-Aug-10 6:51
Steven Solberg21-Aug-10 6:51 
GeneralRe: Threading for multicore applications Pin
harold aptroot21-Aug-10 7:02
harold aptroot21-Aug-10 7:02 
GeneralRe: Threading for multicore applications Pin
Steven Solberg21-Aug-10 7:05
Steven Solberg21-Aug-10 7:05 
GeneralRe: Threading for multicore applications Pin
harold aptroot21-Aug-10 7:11
harold aptroot21-Aug-10 7:11 
GeneralRe: Threading for multicore applications Pin
Steven Solberg21-Aug-10 7:25
Steven Solberg21-Aug-10 7:25 
GeneralRe: Threading for multicore applications Pin
harold aptroot21-Aug-10 7:27
harold aptroot21-Aug-10 7:27 
GeneralRe: Threading for multicore applications Pin
Steven Solberg21-Aug-10 7:47
Steven Solberg21-Aug-10 7:47 
GeneralRe: Threading for multicore applications Pin
harold aptroot21-Aug-10 7:57
harold aptroot21-Aug-10 7:57 
GeneralRe: Threading for multicore applications Pin
Steven Solberg21-Aug-10 8:03
Steven Solberg21-Aug-10 8:03 
GeneralRe: Threading for multicore applications Pin
harold aptroot21-Aug-10 8:28
harold aptroot21-Aug-10 8:28 
AnswerRe: Threading for multicore applications Pin
Luc Pattyn21-Aug-10 10:02
sitebuilderLuc Pattyn21-Aug-10 10:02 
GeneralRe: Threading for multicore applications Pin
Steven Solberg22-Aug-10 8:17
Steven Solberg22-Aug-10 8:17 
GeneralRe: Threading for multicore applications Pin
Luc Pattyn22-Aug-10 8:47
sitebuilderLuc Pattyn22-Aug-10 8:47 
GeneralRe: Threading for multicore applications Pin
Steven Solberg22-Aug-10 8:57
Steven Solberg22-Aug-10 8:57 

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.