[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Setting thread priority
From: |
David Sugar |
Subject: |
Re: Setting thread priority |
Date: |
Sun, 12 Oct 2003 11:40:41 -0400 |
User-agent: |
KMail/1.5 |
If you use a stack size of "0", a default stack size is selected. I think in
the Linux kernel environment, since a thread is a seperate process, the stack
automatically grows in it's own virtual space, so it is not important to use
stack size there. However, if you think you will have a lot of automatic
variables and deep subroutine nesting, you should consider passing an
appropriate stack size, so that the code will work and not crash on platforms
other than GNU/Linux :). FreeBSD, in particular, requires a valid stack for
each thread, and the default size it uses if you pass 0 may be a bit small.
The other issue to consider is that, depending on the compiler and target
platform involved, when a thread exits, the stack frame of the thread
(starting from the "run" method) will NOT be un would, and hence automatic
objects and classes will NOT have their destructors called automatically.
Sometimes, for this reason, it is best to have a flag or variable that the
run method can look at to see when to exit, and then have it fall through a
return, or have the run method selectivily establish it's own cancellation
points and call subroutines which are themselves NOT cancellation points, as
this assures the stack frame will be clean and automatic objects will be
destroyed since final cancellation can only occur when not in a subroutine,
assuming your run method itself creates no additional automatic objects. I
tend to not use automatic objects at all from my run methods....
As for thread priority, higher is "better", or the reverse of "nice". Some
platforms only known three priorities, "higher" than the base process, the
same, or "lower".
On Thursday 09 October 2003 01:35 am, Julie Russell wrote:
> Hi Everyone!
>
> Thanks for all the advice, I've got the libraries installed now! I am
> trying to run a thread in an x11 application, using Xine in one window and
> x11 libraries in the other. Xine uses multi-threading and I am using common
> threads to run the other window, however I am experiencing deadlocking. I
> want to set the priority of the thread I created to fairly low, however I
> couldn't find any documentation on what an average low priority is. Does
> anyone know what priority I would be looking at? Also, I noticed that the
> constructor of Thread not only takes a priority but a stack size. I am just
> learning C++, what stack size would I be looking at setting? Or is there a
> default? Does anyone have any suggestions on how else to prevent
> deadlocking? I am guessing that they both want to share the video driver,
> but I am not sure and have no control over the other threads in the
> application, only the one I created.
>
> Thanks again,
> Julie.
>
>
>
>
>
> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-commoncpp