[XForms] Threads and events
Jeff
wd4nmq at comcast.net
Fri Feb 27 12:50:08 EST 2004
I hope what I am about to ask makes sense, but here goes.
I wrote an app in xforms that had a thread. The thread accessed a server
and then filled in a browser object. Now, due to problems with with GL,
if I remember the reason, and this is the code I used.
while(1){
timeout.tv_sec = 0;
timeout.tv_usec = 1000;
select(0, NULL, NULL, NULL, &timeout);
pthread_mutex_lock(&browserLock);
fl_check_forms();
pthread_mutex_unlock(&browserLock);
}
The thread then uses
pthread_mutex_lock(&browserLock);
// Update the browser
pthread_mutex_unlock(&browserLock);
To write to the browser.
The server access was a thread so as not to lock out user input will the
server was found, accessed and data gotten. Once the data was rceived,
the thread wrote it to the browser object.
I just got finished doing a Windows project that involved kinda the same
thing. A gui thread and a worker thread. Now, in this I was able to use
the Windows API call PostThreadMessage() for the gui to send send
requests to the thread in response to user requests and the thread used
PostMessage() to talk to the gui.
In the case above the gui would use PostThreadMessage() to tell the
thread to access the server. The thread would get the data from the
server and place it in memory and use PostMessage() back to the gui,
giving it the pointer, telling it to display the data in the browser.
Now, since the thread never calls ANY object controls, only the gui
thread does that, there would be no conflict between the two accessing
the gui objects.
Now for the question. Can the Windows API method of messaging be
duplicated with events some how in the X/xforms environment?
This would allow a total seperation of gui and worker thread and neither
would have to wait on a mutex.
Of course, in windows you have window handles and thread ids that are
used to know where to post the messages to. Can you do the same thing in
X to direct events?
Needles to say, I don't know very much, if anything , about the way X
handles events.
One theory is to have an event callback function, and the other thread
post the event to call it to that threads event handler. Is that a
possiblity? Only the gui would use events. A worker thread could use
what I do now to get input from the gui, a queue, queue access mutex,
and a conditional wait on the mutex.
This got kinda long winded and I apologize for that. But, I really would
like to know if this can be done.
Thank you just for reading this long post.
Jeff
wd4nmq at comcast.net
More information about the Xforms
mailing list