DrawFunc and PtEnter()

We have a multi-threaded app that uses PtRaw widgets. I’m getting a strange
application error and in tracking it down I’ve noticed that I have one
thread which has performed a PtEnter(0) and then called PtClippedBlit. The
thread is frozen in that call. At the same time, a draw function has been
called and is active. I can step through it, but some of our application
code gets a bit wacked out.

But this seems odd. 0 doesn’t seem to be a valid value for PtEnter(); I
need to talk to one of the developers to see why they did this. Let’s say
though that it is valid. The draw function shouldn’t be called, should it?
There doesn’t appear to be anything under the draw function (like a SetArgs
or anything) that would ‘implicitly’ call the draw function.

Patrick_Mueller@oti.com

Patrick Mueller <Patrick_Mueller@oti.com> wrote:

We have a multi-threaded app that uses PtRaw widgets. I’m getting a strange
application error and in tracking it down I’ve noticed that I have one
thread which has performed a PtEnter(0) and then called PtClippedBlit. The
thread is frozen in that call. At the same time, a draw function has been

By “frozen” do you mean blocked? What is it blocked on according to pidin?

called and is active. I can step through it, but some of our application
code gets a bit wacked out.

But this seems odd. 0 doesn’t seem to be a valid value for PtEnter(); I

Zero is a perfectly valid value for PtEnter().

need to talk to one of the developers to see why they did this. Let’s say
though that it is valid. The draw function shouldn’t be called, should it?

The library should not call a draw function while another thread has the
lock.

There doesn’t appear to be anything under the draw function (like a SetArgs
or anything) that would ‘implicitly’ call the draw function.

The only plausible explanation that comes to mind involves a mistake on
your side:

PtClippedBlit() does call PtFlush(), which in turn may end up
calling your draw function…

Are you sure those are two different threads that you’re talking
about? :slight_smile:

\

Wojtek Lerch (wojtek@qnx.com) QNX Software Systems Ltd.

Patrick Mueller <> Patrick_Mueller@oti.com> > wrote:
We have a multi-threaded app that uses PtRaw widgets. I’m getting a
strange
application error and in tracking it down I’ve noticed that I have one
thread which has performed a PtEnter(0) and then called PtClippedBlit.
The
thread is frozen in that call. At the same time, a draw function has
been

By “frozen” do you mean blocked? What is it blocked on according to
pidin?

Yes, blocked. We are inside of PtClippedBlit, and the thread is blocked.
Actually, I don’t have a good way of associating my applications threads
with the OS ones. I will see if there’s some way for me to do this. Given
my email address, you probably know what I’m working on :slight_smile:. So I don’t
know specifically what it is blocked on.

But this seems odd. 0 doesn’t seem to be a valid value for PtEnter(); I

Zero is a perfectly valid value for PtEnter().

The docs indicate the parm can be one of:
Pt_EVENT_PROCESS_ALLOW == 1
Pt_EVENT_PROCESS_PREVENT == 2

What does 0 mean? The doc for PtEnter() should be updated to indicate this.
I actually changed all of our usages to 2 and nothing changed.

need to talk to one of the developers to see why they did this. Let’s
say
though that it is valid. The draw function shouldn’t be called, should
it?

The library should not call a draw function while another thread has the
lock.

There doesn’t appear to be anything under the draw function (like a
SetArgs
or anything) that would ‘implicitly’ call the draw function.

The only plausible explanation that comes to mind involves a mistake on
your side:

PtClippedBlit() does call PtFlush(), which in turn may end up
calling your draw function…

Are you sure those are two different threads that you’re talking
about? > :slight_smile:

Yes, the PtClippedBlit() has blocked one thread, and the other thread is in
the draw function. The draw function is running on the ‘main’ thread (the
one processing the Photon event queue), the PtClippedBlit running on a
different thread.

I assume if my draw function was invoked, but then a thread switch occurred
and I tried to do a PtEnter(0) on this different thread, the PtEnter(0) call
would block until the draw function was complete? Or do I need to put an
explicit PtEnter(0) in my draw function? Or must I never put a PtEnter(0)
in my draw function? Or any callback for that matter (plain-old widget
callback, input callback, draw function, workproc???)

I’m guessing that we may have screwed the system somehow shortly before this
happened, and we are seeing symptoms of
hosing the innards of the Photon runtime …

And again, what I’m actually seeing is not a Photon problem, but a strange
application error that I can’t really account for. Wild pointer accesses
perhaps. In debugging the state of the problem, I noticed this odd set of
Photon thread interactions and it just didn’t seem right …

Patrick_Mueller@oti.com

Patrick Mueller <Patrick_Mueller@oti.com> wrote:

The docs indicate the parm can be one of:
Pt_EVENT_PROCESS_ALLOW == 1
Pt_EVENT_PROCESS_PREVENT == 2

What does 0 mean?

Don’t change the thread’s event reading status. And you’re
right, this wants documenting. Knowing Steve Reid, he’s probably
changing the inhouse version as you read this… :slight_smile:



Norbert Black
QSSL Training Services

Patrick Mueller <Patrick_Mueller@oti.com> wrote:

Patrick Mueller <> Patrick_Mueller@oti.com> > wrote:
We have a multi-threaded app that uses PtRaw widgets. I’m getting a
strange
application error and in tracking it down I’ve noticed that I have one
thread which has performed a PtEnter(0) and then called PtClippedBlit.
The
thread is frozen in that call. At the same time, a draw function has
been

By “frozen” do you mean blocked? What is it blocked on according to
pidin?

Yes, blocked. We are inside of PtClippedBlit, and the thread is blocked.
Actually, I don’t have a good way of associating my applications threads
with the OS ones. I will see if there’s some way for me to do this. Given
my email address, you probably know what I’m working on > :slight_smile:> . So I don’t
know specifically what it is blocked on.

It might help to know which blocked state the thread is in. For
instance, if it’s blocked inside PtEnter(), it should be
CONDVAR-blocked.

But this seems odd. 0 doesn’t seem to be a valid value for PtEnter(); I

Zero is a perfectly valid value for PtEnter().

The docs indicate the parm can be one of:
Pt_EVENT_PROCESS_ALLOW == 1
Pt_EVENT_PROCESS_PREVENT == 2

What does 0 mean? The doc for PtEnter() should be updated to indicate this.
I actually changed all of our usages to 2 and nothing changed.

My copy of the docs says:

The value of flags can be one of:

In most cases, it’s better to pass zero for flags, in which case the
thread’s status as event reader or nonreader doesn’t change.

Perhaps it would be clearer if the first sentence was

The value of flags can be zero or one of

Are you sure those are two different threads that you’re talking
about? > :slight_smile:

Yes, the PtClippedBlit() has blocked one thread, and the other thread is in
the draw function. The draw function is running on the ‘main’ thread (the
one processing the Photon event queue), the PtClippedBlit running on a
different thread.

I assume if my draw function was invoked, but then a thread switch occurred
and I tried to do a PtEnter(0) on this different thread, the PtEnter(0) call
would block until the draw function was complete? Or do I need to put an

Yes. A draw function runs with

explicit PtEnter(0) in my draw function? Or must I never put a PtEnter(0)

Calling PtEnter() from a draw function is pointless but harmless: since
a draw function is invoked by a thread that already has the lock,
PtEnter() will fail.

OTOH, calling PtLeave() from a draw function guarantees trouble.

in my draw function? Or any callback for that matter (plain-old widget
callback, input callback, draw function, workproc???)

Whenever the Photon library calls your code, the calling thread already
owns the lock, and a call to PtEnter() will fail. Depending on the
callback, it may be safe to call PtLeave() from your code, provided you
call PtEnter() before returning. This can be done in most of the
callback types you listed, but not in a PtRaw draw function. A draw
function (as well as several other widget class methods that PtRaw turns
into user-level callbacks) is not allowed to do pretty much anything
that may end up modifying the state of any widgets – and a call to
PtLeave() does let other threads modify widgets.

I’m guessing that we may have screwed the system somehow shortly before this
happened, and we are seeing symptoms of
hosing the innards of the Photon runtime …

That’s a possibility…

And again, what I’m actually seeing is not a Photon problem, but a strange
application error that I can’t really account for. Wild pointer accesses
perhaps. In debugging the state of the problem, I noticed this odd set of
Photon thread interactions and it just didn’t seem right …

Another easy way to screw things up is by having a callback that calls
PtEnter(), ignores its failure, and then calls PtLeave() and returns.


Wojtek Lerch (wojtek@qnx.com) QNX Software Systems Ltd.

Norbert Black <nblack@qnx.com> wrote:
: Don’t change the thread’s event reading status. And you’re
: right, this wants documenting. Knowing Steve Reid, he’s probably
: changing the inhouse version as you read this… :slight_smile:

You bet!


Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems