473,410 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

I've painted myself into a corner!

I had written a debugging/trace loggin class that l have been using to
test and develope my applications...
At first the application was tested and ran as a single thread, with all
output going to a single file, but now the application has been expanded
to run in multiple threads...

the debug class was instantiated as a global variable outside of main
and all classes used this external variable to dump there output to...
something like 'cerr'

Well this was fine while I was only dealing with a single thread...
However now I need that each thread's output go to a different file...

Assuming for simplicity sake that all the classes had 'cerr' hard coded
into them as the location to dump log
messages to...
What would you do to the 'cerr' class in order for each thread to have
it's own output?

TIA
\

Jul 22 '05 #1
4 1288
JustSomeGuy wrote:
I had written a debugging/trace loggin class that l have been using to
test and develope my applications...
Sounds like a great place to start writing unit tests on your code.
At first the application was tested and ran as a single thread, with all
output going to a single file, but now the application has been expanded
to run in multiple threads...
Why multiple threads?
What would you do to the 'cerr' class in order for each thread to have
it's own output?


Get on a newsgroup covering threads for your platform, and ask about "thread
local storage". You can create one file handle per thread.

Alternately, add another thread. All the worker threads push loggable items
into a queue, and the other thread (maybe lower priority) pops items out of
the queue and logs them.

But try to take the threads out first. An event driven architecture is
always better.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #2
JustSomeGuy wrote:

I had written a debugging/trace loggin class that l have been using to
test and develope my applications...
At first the application was tested and ran as a single thread, with all
output going to a single file, but now the application has been expanded
to run in multiple threads...

the debug class was instantiated as a global variable outside of main
and all classes used this external variable to dump there output to...
something like 'cerr'

Well this was fine while I was only dealing with a single thread...
However now I need that each thread's output go to a different file...

Assuming for simplicity sake that all the classes had 'cerr' hard coded
into them as the location to dump log
messages to...
What would you do to the 'cerr' class in order for each thread to have
it's own output?

TIA
\


There is no C++ answer to your question, as there isn't any notion of threads
in the language.

You will need to refer to your operating system documentation to see what
impact it has on your C++ std library and what mechanism are available for
thread-local storage.

<off-topic> If you are running under Windows, look at __declspec(thread).
</off-topic>
Jul 22 '05 #3
> What would you do to the 'cerr' class in order for each thread to have
it's own output?


Without knowing just how your class works, it's a little hard to say.
But, however it is that you are getting messages to your logging
class, maybe you could simply add a parameter to specify which file to
write to. For example, if you had one global instance that you tell
to write to a log using a function like this:

gLoggerInstance.writeThisMessage("Error X happened");

and it automatically writes to a particular file, try something like
this instead:

gLoggerInstance.writeThisMessage("Error X happened", "file.txt");

and provide a different file name for messages originating from each
thread. Internally, keep a list where the nodes contain both an
ofstream (or whatever you want to use) and a string containing the
file name. When writeThisMessage() is called, search the list for the
file name. If it is found, write the message to the file. If it is
not, create the file, add it to your list... and write the message of
course.

I don't know if this is really what you were looking for but I hope it
helps.

-Brandon
Jul 22 '05 #4
JustSomeGuy <No***@ucalgary.ca> wrote:
What would you do to the 'cerr' class in order for each thread to have
it's own output?


First of all, "cerr" is not a class: it is an object of type 'std::ostream'.
If you hardcoded 'std::cerr' in loads of places and now have to split it
into various files, you can create a new stream buffer (ie. a class derived
from 'std::streambuf') which writes stuff to a location depending no the
thread (assuming you can figure out the current thread and map that to the
location). You would than install this stream buffer into 'std::cerr' using
the 'rdbuf()' method. Of course, you still need to handle synchronization
of mutating accesses to the 'std::cerr' object between the various threads.

I have posted various examples of how to create stream buffers to this
newsgroups and to comp.lang.c++.moderated. Details on accessing thread
attributes aer off-topic in this forum such that you have to go to
platform specific forum for this stuff.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: bugbear | last post by:
A piece of text was disappearing on one of my pages. Careful editing down shows that any content following a floated-then-cleared element flips things, so that the background of the outer element...
9
by: George Hardy | last post by:
Hi all, This is a bit of an academic question for you smarties out there.... I inherited this application that had 40 forms, 120 datasets, and no dll's. I am starting to separate this app (ie:...
8
by: Prakash | last post by:
I have a msgbox in my form activate event with an OK button. However the msgbox shows up BEFORE the form is painted. I would like the msgbox to be visible after the form gets painted on...
2
by: Crirus | last post by:
hello I have apicturebox painted in it's paint event. I need a way to save the image created. Image obj of my picturebox is Nothing. How to output to a jpg my image? Crirus
12
by: Dean Slindee | last post by:
In all instances where I show a form inside a control (tabpage, panel), the controls within the shown form are stretched vertically about 5% from the original. That is, if a textbox with an actual...
4
by: hzgt9b | last post by:
Using VB .NET 2003, I have a windows application that performs a series of file actions (copy, move, delete) but the actions are completing before the window is painted on the screen... how can I...
3
by: citronelu | last post by:
Hi, I'm new to wxpython, and the following code is my first serious attempt: #~ start code import wx class MyPanel(wx.Panel):
6
by: Nayan | last post by:
I have been working on a card game (called Uno) for past few days. Language used : C# 2.0 When I start a new game, a dialog window pops up asking the name of the player. I enter the name, and...
0
by: =?Utf-8?B?QW5pbCBNb2Rlc3Q=?= | last post by:
I have a div control on my web page which to which i assign a XML document which contains a HTML table as innerHTML, but sometimes table will not get painted on web page. Although the same get...
0
by: =?Utf-8?B?UmljaA==?= | last post by:
In a datagridview, the first column header cell is columnHeader(0), which is immediately to the right of the Top Left Corner Select All cell. And the first RowHeader cell is RowHeaderCell(0) which...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.