Multithreading question

Hello,

I have a small program with a form control and two threads. These two threads are identical with only difference is the first one reads the top part of the SQL table, while the other one reads bottom part. Both use the same DLL (that I include using imports statement) and instantiate the same class within their code areas. Now, I want these two threads to use dll and do the work simultaneously. But, they seem to take turns. (I have a counter on the form for both ). I see that when one starts, the other one stops. When the second starts, the first stops. How do I make both run at the same time. They use same table for reading and updating the DB.

Thanks in advance,
Noorul


Answer this question

Multithreading question

  • Anand Raman - MSFT

    If I have two identical processes doing same work, they both run concurrently, but not with 1 process with 2 threads (atleast 2 processes perform faster than 2 threads, each of them wait quite a bit of time before it starts processing). I guess we have to get multicore processor now. Thinkin of migrating to solaris and Sun Fire servers. Hope that it would solve our problems.

    Regards,
    Noorul

  • Debabrata.debroy

    The simple answer is to get a multi-core or multi-CPU machine. A CPU efectively runs only one thing at a time, so multithreading on a single-core machine only makes it appear that stuff is running simultaneously. It's not.



  • Stephan Harper

    Ok,
    Here is what I am doing.

    I am actually sending SMS using DLL (a classical DLL written with winsock in vb6) over Short Message Peer to Peer over TCP connection.

    Concurrently, I mean there would be switching involved, but two process is doing better performance than multithreaded one.

    I commented out the sending part using the library, it ran very fast. So, I think its the DLL to be blamed. After sending few thousand messages, one of the thread stops and hangs the application. The socket server is multithreaded (actually an SMSC of Mobile Network). Any ideas I don't think sql connection is any problem.

    Thanks,
    Noorul

  • minhhoang

    No they do not. Processes and threads cannot run concurrently on a single-core box, they run one after the other, just switching very, very fast. In any case, it is far more efficient to have as few context switches as possible, no matter what OS/platform you're on. Simply put, your misunderstanding of multithreading will get you into the same trouble on Solaris as it would on Windows.

    Ideally, for best performance, any application should have one active thread per core.



  • __murph__

    Are you trying to use the same SqlConnection object instance in both threads

  • Multithreading question