Thread: Com port access in two threads..

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    175

    Com port access in two threads..

    I am developing a serial communication utility in VC++, which is Windows console application.

    I am creating a communication port in main thread. And I use com port handle in main thread and in another thread spawned by main thread.

    Do I really need to synchronise com port access in both threads by mutex? What is side effect, if I do not synchronise com port access, in thread spanwned by main thread?

    Please let me know.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well obviously if one thread is writing to the port and suddenly the second begins writing too for instance...you have a problem.
    In cases like this, sinchronization is not just an option - it's mandatory! You might check out 'Multithreading Applications in Win32' by Beveridge and Weiner.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My TCP Port Scanner in C
    By billy786 in forum Networking/Device Communication
    Replies: 5
    Last Post: 06-28-2008, 07:12 PM
  2. Reading and writing to a serial port
    By SwarfEye in forum C Programming
    Replies: 2
    Last Post: 08-18-2006, 12:28 AM
  3. faster port access
    By the_head in forum C Programming
    Replies: 5
    Last Post: 10-22-2004, 05:38 PM
  4. problem with win32 threads
    By pdmarshall in forum C++ Programming
    Replies: 6
    Last Post: 07-29-2004, 02:39 PM
  5. Need help to access COM port in C++
    By rizmayo in forum C++ Programming
    Replies: 2
    Last Post: 09-12-2001, 02:47 AM