Com port access in two threads..

This is a discussion on Com port access in two threads.. within the C Programming forums, part of the General Programming Boards category; I am developing a serial communication utility in VC++, which is Windows console application. I am creating a communication port ...

  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
    Posts
    5,439
    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:
    int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000
    <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan
    (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000
    )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21