multi-thread win32 programming

This is a discussion on multi-thread win32 programming within the Windows Programming forums, part of the Platform Specific Boards category; Quote: any chance and you can answer my 2nd question about the blinking windows? or is it too complex? coz ...

  1. #16
    Registered User
    Join Date
    Jan 2008
    Posts
    28
    Quote:
    any chance and you can answer my 2nd question about the blinking windows? or is it too complex? coz i dont have to do it but i would like to.....

    Well, Windows programming is difficult. It's hard to say right out of the bat what's wrong.
    yes, it is difficult.. but ive seen it happen pretty much on every program me or any of my friends wrote so i though it was something to do with the time it takes the program to redrew everything on resize but then again on every commercial program it doesnt happen... so there must be something to be done. but thats ok for now. i can give it a rest and figure it out at another time.

  2. #17
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,630
    This tutorial covers common causes and fixes for flickering windows.

    http://catch22.net/tuts/flicker.asp

    gg

  3. #18
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by Elysia View Post
    Avoid global variables! They are not thread safe, sometimes they aren't optimized and they are hard to keep track of and easily creates bugs!
    Just an advice for you.
    Elysa, you are a programming noob, why the hell don't you know anything! :/

    If you need to use a global variable with a thread, declare the varible as volatile.
    Just be aware that multiple threads may access it at the same time. If two or more threads need to use a shared item, use CRITICAL_SECTION's.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  4. #19
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    Quote Originally Posted by abachler View Post
    Elysa, you are a programming noob, why the hell don't you know anything! :/
    Yeah, right

    If you need to use a global variable with a thread, declare the varible as volatile.
    Just be aware that multiple threads may access it at the same time. If two or more threads need to use a shared item, use CRITICAL_SECTION's.
    This was discussed before. Volatile is pretty much compiler implementation defined, unknown territory. And you don't need volatile if there's just one thread accessing it!
    If two threads are accessing it, THEN you need locks.
    But this still makes them bad because of other reasons I pointed out. Some globals just aren't optimized, and they can create hard-to-maintain code in larger projects.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by Elysia View Post
    This was discussed before.
    and for all the reasons that where discussed, globals are not inherently bad. People misuse globals just as they misuse templates or classes, that doesnt make them bad. Poor programming does not make a feature 'bad'. There are many times when globals can easily solve a problem that would otherwise be convoluted or quite frankly impossible to solve. Ultimately there will always be at least some data that MUST be global for any serious project to function. If I have 50 thread functions that all access a common database, I certainly do NOT want to maintain that database seperately for each thread. The simple solution is a global variable. If someone has problems reading -

    Code:
    extern LPVOID pDatabase;
    then they shouldnt be programming in the first place. If they cant find the initial declaration, perhaps they need to check oh, I dont know 'declarations.cpp' or some such.

    Crappy programmers shouldn't breathe, that would save us all a lot of problems with people crying about global variables. If you cant handle globals, or you can't use them properly, then don't use them, but don't make high and mighty claims that they are therefore 'BAD'.
    Last edited by abachler; 01-15-2008 at 03:10 PM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  6. #21
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    IMO it is a very bad idea to have two threads running on the same UI. Most controls are not thread safe.

    Quote Originally Posted by Codeplug View Post
    This tutorial covers common causes and fixes for flickering windows.

    http://catch22.net/tuts/flicker.asp

    gg
    One thing it misses is to use both

    InvalidateRect();//set area to be redrawn
    UpdateWindow();//bypass the OS message queue and post directly to the windows callback

    This makes the paint message non-queued for faster drawing (as paint messages will be ignored and concatenated in the OS msg queue).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #22
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,630
    Quote Originally Posted by Elysia View Post
    This was discussed before.
    I believe "this" is in reference to the use of volatile. The volatile keyword has nothing to do with multi-threaded programming....unless your compiler says it does (I only know of one compiler that does).

    Discussed before here:
    MSDN volatile sample
    synchronization and volatile

    gg

  8. #23
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    Quote Originally Posted by abachler View Post
    and for all the reasons that where discussed, globals are not inherently bad. People misuse globals just as they misuse templates or classes, that doesnt make them bad. Poor programming does not make a feature 'bad'. There are many times when globals can easily solve a problem that would otherwise be convoluted or quite frankly impossible to solve. Ultimately there will always be at least some data that MUST be global for any serious project to function. If I have 50 thread functions that all access a common database, I certainly do NOT want to maintain that database seperately for each thread. The simple solution is a global variable. If someone has problems reading -

    Code:
    extern LPVOID pDatabase;
    then they shouldnt be programming in the first place. If they cant find the initial declaration, perhaps they need to check oh, I dont know 'declarations.cpp' or some such.

    Crappy programmers shouldn't breathe, that would save us all a lot of problems with people crying about global variables. If you cant handle globals, or you can't use them properly, then don't use them, but don't make high and mighty claims that they are therefore 'BAD'.
    I do agree, but usually they are misused. If they didn't have a purpose, they wouldn't exist, obviously.

    Quote Originally Posted by Codeplug View Post
    I believe "this" is in reference to the use of volatile. The volatile keyword has nothing to do with multi-threaded programming....unless your compiler says it does (I only know of one compiler that does).

    Discussed before here:
    MSDN volatile sample
    synchronization and volatile

    gg
    That's mostly what I was referring to. Volatile is a tricky subject. I don't use them at all and it works fine. So the must have or not can be a tricky question already discussed to great lengths.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multithreading (flag stopping a thread, ring buffer) volatile
    By ShwangShwing in forum C Programming
    Replies: 3
    Last Post: 05-19-2009, 07:27 AM
  2. Replies: 2
    Last Post: 07-01-2007, 07:11 AM
  3. Thread Synchronization in Win32
    By passionate_guy in forum C Programming
    Replies: 0
    Last Post: 02-06-2006, 04:34 AM
  4. multithreading question
    By ichijoji in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2005, 10:59 PM
  5. Replies: 12
    Last Post: 05-17-2003, 05:58 AM

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