+ Post New Thread
Results 1 to 2 of 2
  1. #1
    Full Member level 5
    Points: 3,109, Level: 13
    Achievements:
    7 years registered

    Join Date
    Feb 2008
    Location
    Turkiye
    Posts
    255
    Helped
    59 / 59
    Points
    3,109
    Level
    13

    Thread-safe usage of logger

    Hi colleagues;
    I want to use a logger lib for my application in C. I found this on github, it seems quite fit my purposes. My question, how can i use it thread-safely?
    In my application, i have two threads and both uses logger function (to print a file or stderr). Author gives a function for this purpose -log_set_lock(log_LockFn fn)- but i couldn't figure out how to use it?
    https://github.com/rxi/log.c/#log_set_locklog_lockfn-fn
    log_set_lock(log_LockFn fn)

    If the log will be written to from multiple threads a lock function can be set. The function is passed a udata value (set by log_set_udata()) and the integer 1 if the lock should be acquired or 0 if the lock should be released.
    Thanks for help

    •   Alt15th April 2018, 11:15

      advertising

        
       

  2. #2
    Newbie level 2
    Points: 20, Level: 1

    Join Date
    Apr 2018
    Posts
    2
    Helped
    0 / 0
    Points
    20
    Level
    1

    Re: Thread-safe usage of logger

    I suggest to create another thread for logging/printing purposes only (to a file or stderr) with a FIFO.
    This thread would be woken up only when something is in the FIFO. The content of this FIFO would be logged/printed.
    Then other threads could write theirs records into that FIFO to make theirs log.



--[[ ]]--