fprintf _lock_file EnterCriticalSection

This is a discussion on fprintf _lock_file EnterCriticalSection within the C Programming forums, part of the General Programming Boards category; hello. my program hangs inside an fprintf. debugger follows it to procedure _lock_file where it never escapes from. i believe ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    2

    fprintf _lock_file EnterCriticalSection

    hello. my program hangs inside an fprintf. debugger follows it to procedure _lock_file where it never escapes from. i believe the final executed command is EnterCriticalSection( &(((_FILEX *)pf)->lock) );

    anyone know why this is happening? the filepath associated with the file pointer seems valid and i didnt get any error messages opening the file. thank you for your time.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Well you didn't mention which OS/Compiler you're using.
    Nor did you post a simple program which demonstrates the fault.
    Nor did you mention for example whether you were using threads in your program.

    Two scenarios,
    1. Your code is full of bugs, and it's managed to trash the library data structures into thinking there is a file lock, when there isn't.
    2. You've mixed thread-safe and non thread-safe code in a threaded program, and the collective mis-understanding is what you're seeing.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    fprintf is thread safe, so it enters a critical section whenever you try to write to a file.
    So if another thread is trying to write to the same file and somehow hangs/fails/takes time, your thread will be blocked until the other thread is finished.
    So as Salem mentions, show some code to illustrate the problem.
    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.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2
    thank you for your time. no threads here so i understand therefor it must be a bug as you say. i'm bubblesorting arrays of structs of files pointers numerous times so i must have damaged a file pointer somewhere. you've helped me and i appreciate it. thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with basic program
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 02-01-2006, 03:19 PM
  2. program not working...please look at this
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 01-30-2006, 09:33 PM
  3. sprintf and fprintf segmentation error
    By kona1 in forum C Programming
    Replies: 5
    Last Post: 06-21-2005, 10:55 AM
  4. fprintf to stderr crash programs
    By jlai in forum Windows Programming
    Replies: 2
    Last Post: 04-12-2005, 08:51 AM
  5. fprintf
    By bennyandthejets in forum Windows Programming
    Replies: 10
    Last Post: 11-16-2002, 05:58 PM

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