Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#12391 closed Bugs (invalid)

Visual Studio 2010 hangs up when linking boost log object

Reported by: xinyan.zhang@… Owned by: Andrey Semashev
Milestone: To Be Determined Component: log
Version: Boost 1.61.0 Severity: Problem
Keywords: Visual Studio 2010 Cc:

Description

I am using Visual Studio 2010 with SP1. I met a very strange problem: Visual Studio 2010 hangs up when linking boost log object. There is a work-around -- stop the building and restart it. Then it will success.

I found if I set the second parameter "start_thread" to false in my sink ctor, and start thread explicitly, this problem disappears. But the second problem appears -- the application hangs up at run time. I have to remove the line "fileSink->run();". Then it does not hang up in either building and run time.

My question is if I does not start thread for asynchronous_sink, is there any problem or any impact to the performance? Any way, I can still see the log record. Thank you.

        typedef boost::log::sinks::asynchronous_sink< boost::log::sinks::text_file_backend > text_sink;
        boost::shared_ptr< text_sink > fileSink;
	boost::shared_ptr< sinks::text_file_backend > backend =
	boost::make_shared< sinks::text_file_backend >(
			boost::log::keywords::file_name = filePath,
			boost::log::keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0) //file rotation every day at midnight
			);
	
	fileSink.reset(new text_sink(backend, false)); // hangs up during linking object, if set to true

        //fileSink->run();  // hangs up during rum time

Change History (4)

comment:1 by Andrey Semashev, 6 years ago

Resolution: invalid
Status: newclosed

run() should be called in the dedicated thread that is supposed to process log records. When you pass start_thread = true that's effectively what the internal feeding thread does. If you don't start the internal thread, don't call run or feed_records then your log records will pile up in the queue not being processed.

Regarding the compiler hang I suggest you report it to Microsoft.

comment:2 by xinyan.zhang@…, 6 years ago

Without "start_thread=true" or explicitly call "run" or "feed_records", I still get the log record. That is strange. Is that log record incorrect or truncated?

Thank you very much.

comment:3 by Andrey Semashev, 6 years ago

You could also be calling flush() which forces the buffered records to be processed at the point of this call. Other than that I can't see how records could appear in the output.

BTW, start_thread is true by default, you have to explicitly set it to false to disable the internal thread.

comment:4 by xinyan.zhang@…, 6 years ago

Yes, my code explicitly calls "flush()" periodically. That's the reason. Thank you very much.

Note: See TracTickets for help on using tickets.