Thread: Threads, Linked Lists, Semaphores, Critical Section ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    10

    Threads, Linked Lists, Semaphores, Critical Section ...

    Hi all,

    I'm having some issues on a multi-thread app. Wonder if ne1 may help me out...

    Since I followed an article from codeguru i'm posting the link directly to the thread as it contextualizes the issue:

    http://www.codeproject.com/threads/s...0&forumid=2285

    My comment is the newest one (arleybls).

    Cheers,
    _Jr-
    Last edited by _jr; 06-20-2006 at 11:17 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    1. It's C++, and not C
    2. It's windows specific
    Thread moved.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    10

    Well..

    Quote Originally Posted by Salem
    1. It's C++, and not C
    2. It's windows specific
    Thread moved.
    The orginal article is indeed in C++, but my app is in C, as u may find on the comment posted by me on the article :-/

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So basically, no replies there so you're going round trying to drum up support by posting back-links in other forums?

    > DWORD dwThreadId[MAX_THREADS]
    This is a local variable
    You pass a pointer to this local variable to a thread
    This function exits, and the local variable disappears
    What do you think will happen when the thread tries to dereference it's pointer?

    > char *strLabel = calloc(HLABEL_SIZE, sizeof(char));
    > printf("String --> %s at l_addr %d \n",strLabel,&strLabel);
    What exactly are you trying to print here?
    The address where the string is stored, or the address of your local variable (you get the 2nd)

    Also, you have an excess of ; at the end of each code block.
    You don't need ; after a brace in code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    10

    thx

    >What do you think will happen when the thread tries to dereference it's pointer?
    Actually, the threads do not use dwThreadId in any way. I will later use it to shut them down..but they're not meant to pass values to the threads, and they don't. They're only used to store the Thread's ID passed back by the CreateThread() function.

    >...your local variable (you get the 2nd)
    That's exactly what I wanna get, as having the same string printed on different variables address means that two distinct threads are receiving the same value. Since I'm using critical section to lock and unlock the FIFO pop/push operations, and the push itself does w8s for a free thread trough events...that was not supposed to happen..and that is exactly the main problem...how the hell do I finish with the same string on two different threads!

    Codeproject post is not a forum but a comment public space to the article itself. As the code is based on the article, it came to me that linking back to it would make more sense than compiling a huge post explaning the problem again. I also did post on Microsoft's public.win32.programmer.kernel, can't see how stressing posting on 2 forums can be...but, sorry anyway.

    ;;;;; u're right, I need to get my code diet...

    Cheers,
    _Jr.
    Last edited by _jr; 06-21-2006 at 11:48 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doubly linked lists
    By mohanlon in forum C Programming
    Replies: 8
    Last Post: 12-08-2010, 01:01 AM
  2. CreateThread ?!
    By Devil Panther in forum Windows Programming
    Replies: 13
    Last Post: 11-15-2005, 10:55 AM
  3. Freeing Linked Lists
    By mrpickle in forum C Programming
    Replies: 4
    Last Post: 01-21-2004, 07:57 PM
  4. Critical Sections, destroying
    By Hunter2 in forum Windows Programming
    Replies: 4
    Last Post: 09-02-2003, 10:36 PM
  5. Dynamic number of linked lists
    By foniks munkee in forum C Programming
    Replies: 2
    Last Post: 02-24-2002, 09:30 PM