Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. design issues multi threading

design issues multi threading

Scheduled Pinned Locked Moved C#
questiondesigndata-structuresbeta-testingannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ekynox
    wrote on last edited by
    #1

    G'day folks, At the moment I am writing a little application which utilities multi threading to do some processing. Essentially, my application creates a fixed number of threads,i.e. 5. Each thread when started performs three main tasks which represents the operational states the thread is in. The operational state is essentially a particular method that is executed to perform the specific task. In my current design I have created a global array which contains five elements to hold each thread's operational state. Each time the thread moves to a new operational state, the thread's operation state value is changed in the array. I have used the correct locking processes on the array when a thread has to update it. Here is some code which shows I how the thread is started: int []operationalStateArray = new int[5]; void Main(string[] args) { Thread[] ThreadArray = new Thread[5]; MyClass myclass = new MyClass(); myclass.FetchStatusArray(ref operationalStateArray); operationalStateArray [0] = 1; //1 implies encoding task ThreadArray[0] = new Thread(new ThreadStart(myclass.ProcessData)); ThreadArray[0].Start(); ThreadArray[0].Join(); } Having explained my application, my question is that: Is the approach I have taken in accessing the global array using threads is okay or are there better solutions? Is it okay to pass operationalStateArray as a reference to be manipulated by the ProcessData method in MyClass? If anyone can give me their feedback on this I would most appreciate it. cheers Vee

    B 1 Reply Last reply
    0
    • E ekynox

      G'day folks, At the moment I am writing a little application which utilities multi threading to do some processing. Essentially, my application creates a fixed number of threads,i.e. 5. Each thread when started performs three main tasks which represents the operational states the thread is in. The operational state is essentially a particular method that is executed to perform the specific task. In my current design I have created a global array which contains five elements to hold each thread's operational state. Each time the thread moves to a new operational state, the thread's operation state value is changed in the array. I have used the correct locking processes on the array when a thread has to update it. Here is some code which shows I how the thread is started: int []operationalStateArray = new int[5]; void Main(string[] args) { Thread[] ThreadArray = new Thread[5]; MyClass myclass = new MyClass(); myclass.FetchStatusArray(ref operationalStateArray); operationalStateArray [0] = 1; //1 implies encoding task ThreadArray[0] = new Thread(new ThreadStart(myclass.ProcessData)); ThreadArray[0].Start(); ThreadArray[0].Join(); } Having explained my application, my question is that: Is the approach I have taken in accessing the global array using threads is okay or are there better solutions? Is it okay to pass operationalStateArray as a reference to be manipulated by the ProcessData method in MyClass? If anyone can give me their feedback on this I would most appreciate it. cheers Vee

      B Offline
      B Offline
      beatles1692
      wrote on last edited by
      #2

      Hi I think that you can have a class (for example Operation) that has a state property ( a readonly property) that gets the state of the operation. Operation class has a ProcessData method that will be used in ThreadStart to start a thread and within this method the operation can change its state. Using this approach , you can have unlimited operations (not only 5 or a known number of operations) and no one can change the state of a opration except an operation itself that means you don't have to be worry about locking you objects and finally there's no need to remember the index of an external array(when an operation wants to change its state) Good Luck

      E 1 Reply Last reply
      0
      • B beatles1692

        Hi I think that you can have a class (for example Operation) that has a state property ( a readonly property) that gets the state of the operation. Operation class has a ProcessData method that will be used in ThreadStart to start a thread and within this method the operation can change its state. Using this approach , you can have unlimited operations (not only 5 or a known number of operations) and no one can change the state of a opration except an operation itself that means you don't have to be worry about locking you objects and finally there's no need to remember the index of an external array(when an operation wants to change its state) Good Luck

        E Offline
        E Offline
        ekynox
        wrote on last edited by
        #3

        thanks for your feedback. I took your solution on board and managed to derive a solution based on event based asynchronous design pattern. I just had to look a bit harder in the local help of VS2005.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups