dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: How to do 2 or more process simultaneously?

  1. #1
    Join Date
    Jan 2008
    Location
    India
    Posts
    780

    How to do 2 or more process simultaneously?

    Hi all,

    i have an list that contains some items say N items.

    i have assigned x number of process to do processing over N List Items.

    for example if (x=2) number of process work on processing of (N=20) List Items, so its start from starting two List items when any process finished first than move on 3 one and so on until last item of List.

    so please help me how can i do this.

    thanks in advance.
    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,603

    Re: How to do 2 or more process simultaneously?

    You need the task list to be shared among processes (typically database of any kind serves to the purpose), or have a dedicated process for list management and other worker processes consuming such dispatching service.
    Best regards,
    Igor

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,559

    Re: How to do 2 or more process simultaneously?

    Why not just have a thread remove an item from the list when it starts processing it.

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: How to do 2 or more process simultaneously?

    It sounds like you want a thread-pool design. Task objects are pushed onto a queue, and as any thread finishes its current work, it checks the queue to see if there are any tasks waiting. If so, it takes one off the queue and begins processing it.

    There are thread-pool libraries out there, but implementing one yourself on top of one of the common threading libraries (pthreads, Boost threads, etc) is an interesting challenge which really makes sure you know your synchronization. Especially when the tasks being run in the thread pool start waiting on other tasks in the pool.....

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,227

    Re: How to do 2 or more process simultaneously?

    If you are coding for windows, you can use the QueueUserWorkItem api - a built in thread pool mechanism.

  6. #6
    Join Date
    Jan 2008
    Location
    India
    Posts
    780

    Re: How to do 2 or more process simultaneously?

    when i use thread its end after execution of one list item? how can i set it like this first only assigned number of threads running and execute function on the bases of list item data, after execution check if list have any other item to be execute than execute this.

    list taking some information that is communicate using ports,

    i am having 2 and more port number for communication.

    one port can use details from list and communicate after finish it use another item to do this ,coz if i want to access the port that is already in use it gives an error of access denied.

    so please help me how can i do this?

    if possible can anybody please provide me any sample or example code.

    thanks in advance.
    Last edited by vjshankwar; July 16th, 2011 at 04:15 AM.
    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)