Thread: simple while loop

  1. #31
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The FindFiles function will loop and not provide any progress until I explicitly ask for it
    Which FindFiles function is that?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #32
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    My custom designed one,
    pp< std::vector<CString> > Stuff::FindFiles(const CString& strFolder, const CString& strPattern, bool bSearchSubFolders, UINT64* pnCurrentFile, CString* pstrCurrentFile, bool bThread, bool* pThreadFinished, bool* pCancel, pp< std::vector<CString> > pBuffer)
    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.

  3. #33
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Well, give it another parameter:
    Code:
    HWND hUpdateWnd
    and whenever you've got a file, do
    Code:
    if(hUpdateWnd) PostMessage(hUpdateWnd, UM_FILEFOUND, 0, 0);
    Note: MFC's classes are thread-bound. Do not pass them to other threads. That's why I use a plain window handle here.
    UM_FILEFOUND is, of course, a constant with a value of WM_USER+x.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #34
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by CornedBee View Post
    Well, give it another parameter:
    Code:
    HWND hUpdateWnd
    and whenever you've got a file, do
    Code:
    if(hUpdateWnd) PostMessage(hUpdateWnd, UM_FILEFOUND, 0, 0);
    That would hinder efficiency. The thing is that I wrote it explicitly so that it wouldn't do anything else than find files unless asked by the caller. And just posting a message doesn't really help.
    I would have to make a buffer and probably pass a struct. But it takes unneccesary time, which is why I made the whole explicitly ask approach.

    Note: MFC's classes are thread-bound. Do not pass them to other threads. That's why I use a plain window handle here.
    UM_FILEFOUND is, of course, a constant with a value of WM_USER+x.
    Yes, I know. MFC classes are generally thread un-safe.
    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. #35
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Compared to searching the hard disk for files, posting a message is nothing. And it's certainly more efficient than another thread polling a global variable.

    You haven't answered yet, by the way: are these globals atomic?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #36
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by CornedBee View Post
    Compared to searching the hard disk for files, posting a message is nothing. And it's certainly more efficient than another thread polling a global variable.
    We'll see about that, I guess...

    You haven't answered yet, by the way: are these globals atomic?
    No, afraid not.
    Code:
    HANDLE heRequestData_CountFiles;
    HANDLE heRequestData_FindFiles;
    bool bRequestData_CountFiles = false;
    bool bRequestData_FindFiles = false;
    I don't know very much about atomic.
    But theoretically, a flag should take a cycle to update. But I don't think that's a good thing to rely on?
    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.

  7. #37
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    No, it's not. Basically, what you have there is a time bomb.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #38
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What do you propose to fix it?
    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.

  9. #39
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Use proper communication methods as I have outlined.

    Or as a bare minimum fix, use the Interlocked* APIs for manipulating the things.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. loop needed also how to make input use letters
    By LoRdHSV1991 in forum C Programming
    Replies: 3
    Last Post: 01-13-2006, 05:39 AM
  2. Trying to figure out a simple loop....
    By chadsxe in forum C++ Programming
    Replies: 9
    Last Post: 01-05-2006, 01:31 PM
  3. simple collision detection problems
    By Mr_Jack in forum Game Programming
    Replies: 0
    Last Post: 03-31-2004, 04:59 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. for loop or while loop
    By slamit93 in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2002, 04:13 AM