[Pb] PtFileSelection run from a Thread

Howdy,

I’m having a bit of difficulty having a PtFileSelection when started
by a thread :frowning:

If I don’t lock the call to PtFileSelection by PtEnter/PtLeave, the
application crash. If I use PtEnter/PtLeave that way :


int flag = PtEnter(Pt_EVENT_PROCESS_ALLOW);
PtFileSelection(_parent,NULL,_title,_root,_spec,NULL,NULL,_format,&_info,_flags)
;
if(flag>=0)
PtLeave(flag);

The PtFileSelection window is display but the list of file stay empty, and
the cursor stay in hourglass style for a while and then the content of
the directory is display , and an error message is display in the
console :

PhEventNext failed: Resource busy

Closing the PtFileSelection lock the main window.

The directory showed by the PtFileSelection contains only 9 items.

Thanks.

Regards,

jean-louis

PtFileSelection calls the Photon mainloop while it is building the filelist,
to ensure that your Photon application still responds to events. However, if
you spend a lot of time in timer callbacks or workprocs, it will slow down
the fileselector drastically.
I attach my correspondance when I had the same problem.
I don’t know about the error message though.


Markus Loffler <loffler@ces.clemson.edu> wrote:

Thanks for you suggestions, Wojtek. I checked them and nothing is wrong, I
call PtInit() only one time, and even could remove PtEnter(), PtLeave()
(widgets are only accessed from the main thread).

Finally, after some digging, I found the root of the problem. I have a
window with a PtRaw widget in it that gets continuously updated, i.e. a
timer callback calls PtDamageWidget. In the draw function of the raw
widget,
I use the PgMem… functions to draw into a shared memory block and then
flush the memory block into the widget using PgDrawImage (double
buffering).



What is happenening is that the continuous redrawing of the widget somehow
“starves” the file selector. The file selector hangs, and as soon as I
move
another window over my PtRaw widget, it catches up. If my update time is
smaller than every 20ms, the file selector hangs before displaying the
items, if I make it bigger than 20ms, it displays the items, but everytime
I
change the directory, some long delay is happening.

PtFileSelection() calls PtBkgdHandlerProcess(), and
PtBkgdHandlerProcess() doesn’t return until you have processed all
pending Photon events. If events are comming faster than you can
process them, PtBkgdHandlerProcess() never returns…

“Jean-Louis Villecroze” <jlv@kirilla.com> wrote in message
news:9gledv$h3p$1@inn.qnx.com

Howdy,

I’m having a bit of difficulty having a PtFileSelection when started
by a thread > :frowning:

If I don’t lock the call to PtFileSelection by PtEnter/PtLeave, the
application crash. If I use PtEnter/PtLeave that way :


int flag = PtEnter(Pt_EVENT_PROCESS_ALLOW);

PtFileSelection(_parent,NULL,_title,_root,_spec,NULL,NULL,_format,&_info,_fl

ags)

;
if(flag>=0)
PtLeave(flag);

The PtFileSelection window is display but the list of file stay empty, and
the cursor stay in hourglass style for a while and then the content of
the directory is display , and an error message is display in the
console :

PhEventNext failed: Resource busy

Closing the PtFileSelection lock the main window.

The directory showed by the PtFileSelection contains only 9 items.

Thanks.

Regards,

jean-louis

Jean-Louis Villecroze <jlv@kirilla.com> wrote:

I’m having a bit of difficulty having a PtFileSelection when started
by a thread > :frowning:

If I don’t lock the call to PtFileSelection by PtEnter/PtLeave, the
application crash. If I use PtEnter/PtLeave that way :



int flag = PtEnter(Pt_EVENT_PROCESS_ALLOW);

Have you tried using zero instead of Pt_EVENT_PROCESS_ALLOW?

PtFileSelection(_parent,NULL,_title,_root,_spec,NULL,NULL,_format,&_info,_flags)
;
if(flag>=0)
PtLeave(flag);

The PtFileSelection window is display but the list of file stay empty, and
the cursor stay in hourglass style for a while and then the content of
the directory is display , and an error message is display in the
console :

PhEventNext failed: Resource busy

I don’t think the Photon library prints out a message like that. Are
you calling PhEventNext() from your code?


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

Received from Jean-Louis Villecroze via email:

Wojtek Lerch <wojtek@qnx.com> wrote:

Jean-Louis Villecroze <> jlv@kirilla.com> > wrote:

int flag = PtEnter(Pt_EVENT_PROCESS_ALLOW);

Have you tried using zero instead of Pt_EVENT_PROCESS_ALLOW?

I tried PtEnter(0) and that didn’t change a things. I also
tried using a PtMainLoop instead of my own loop , and this
gave me the exact same result.

PtFileSelection(_parent,NULL,_title,_root,_spec,NULL,NULL,_format,&_info,_flags)
;
if(flag>=0)
PtLeave(flag);

The PtFileSelection window is display but the list of file stay empty, and
the cursor stay in hourglass style for a while and then the content of
the directory is display , and an error message is display in the
console :

PhEventNext failed: Resource busy

I don’t think the Photon library prints out a message like that. Are
you calling PhEventNext() from your code?

Yes, I’m not using PtMainLoop, maybe I forgot to do something
important in my mainloop ?


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

Jean-Louis Villecroze wrote:

Wojtek Lerch <> wojtek@qnx.com> > wrote:
Jean-Louis Villecroze <> jlv@kirilla.com> > wrote:

int flag = PtEnter(Pt_EVENT_PROCESS_ALLOW);

Have you tried using zero instead of Pt_EVENT_PROCESS_ALLOW?

I tried PtEnter(0) and that didn’t change a things. I also
tried using a PtMainLoop instead of my own loop , and this
gave me the exact same result.

There is a problem with how PtFileSelection() uses
PtBkgdHandlerProcess() that caused it to read the directory horribly
slowly in a multithreaded environment. I would expect that the version
that uses PtMainLoop() will return to a sane state eventually, but you
might need to wait a minute or two…

My first reaction was that Pt_EVENT_PROCESS_ALLOW could be making things
worse, but after giving it more thought I think it does not matter at
all. But in general, I think it’s a good habit to use zero unless you
have a reason not to.

PtFileSelection(_parent,NULL,_title,_root,_spec,NULL,NULL,_format,&_info,_flags)
;
if(flag>=0)
PtLeave(flag);

BTW: If PtEnter() has failed, it’s unsafe to call PtFileSelection()
unless you check that the reason it failed is because you already had
the lock. Something like

flag = PtEnter( 0 );
if ( flag >= 0 || flag == -EDEADLK )
PtFileSelection( … );
if ( flag >= 0 )
PtLeave( flag );

In general I think it’s a good habit to design your code to minimize the
number of functions that don’t know whether the library is locked and
have to rely on the EDEADLK behaviour of PtEnter(). This way, most of
your code can safely assume that PtEnter() returning an error is a bad
thing.

The PtFileSelection window is display but the list of file stay empty, and
the cursor stay in hourglass style for a while and then the content of
the directory is display , and an error message is display in the
console :

PhEventNext failed: Resource busy

I don’t think the Photon library prints out a message like that. Are
you calling PhEventNext() from your code?

Yes, I’m not using PtMainLoop, maybe I forgot to do something
important in my mainloop ?

Well, “forgot” is not exactly the best word. It’s practically
impossible to write your own main loop if you want to use input procs,
workprocs, or PtEnter() and PtLeave(). All these mechanisms (and
probably a few more that I can’t think of at the moment) rely on a
private data structure that is not defined in any of the headers that
you have access to.

\

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