Multi-threaded application

This forum is read only. No new submissions are accepted.

Questions about motif? Contact us

5 posts / 0 new
Last post
Multi-threaded application

Submitted by Anonymous on Mon, 06/11/2001 - 19:52. Developers
I am developing a multi-threaded (pthreads) application that uses the current version of Open Motif. A multi-line text widget is being used as a means to show "progress". This can be accessed by any of the threads using the routine

/* DISPLAY LINE */
/* Description
Displays a line in the progress display.

Passed parameter line - pointer to text to add to display

Returned value none
*/

void DisplayLine(char * line)

{
char display_line[80];

pthread_mutex_lock(&display_mutex);
if (strlen(line) < 78)
strcpy(display_line,line);
else
{
strncpy(display_line,line,78);
display_line[78] = 0;
}
strcat(display_line,"
");
if (XmTextGetLastPosition(list) > 4000)
XmTextSetString(list,display_line);
else
XmTextInsert(list,0,display_line);
pthread_mutex_unlock(&display_mutex);
LogOutput(line);
}

Though this version of Motif is supposed to be thread safe and mutual exclusion is guarrenteed with the mutexes, the application often fails when this routine is called by a thread other then the thread in which the window is displayed. The failure is very strange, the calling thread goes into some kind of continual loop and uses all the CPU time available. This is a port of an application that was implemented and tested under Windows (95/98/NT/2000 and CE) and Java SDK 1.3 (under Windows)with no problem so I am at lost for an explanation. Can anyone give me a hand.

Anonymous

Tess, I`ve been developing using X11R6 and Motif 2.1 on a Solaris 8 machine for almost a year. The multithreadedness of this setup is dubious at best as near as I can tell and I haven`t found much help on the web. Make sure you`ve called XInitThreads() and XtToolkitThreadInitialize() and you compile with the -mt option. I have had some success creating windows in the main thread and then displaying things in them from another thread, but if I try and have multiple threads displaying things in a single window, I get crashes. Even in this case I get occasional crashes during a call to XmListBottomPos() from the main thread so I think something deep in Motif and X must get messed up sometimes.

Not much help, I know...if anyone else out there is doing multithreaded things with Motif, we`d love to hear from you!

Anonymous

I`m not to sure about thread programming on solaris, but I`ve done some on linux 7.0. I`m just guessing here but shouldn`t you check to see if "display_mutex" has already been locked by another thread before you lock it. I can`t really say much without looking at the entire code. Hopes this helps.

Anonymous

Hmmm, I don`t know where I got "solaris" from, omit that first line. If you can provide a little more info. I might be able to further help you.

Anonymous

Have you tried XLockDisplay and XUnlockDisplay in
addition to the mutex locks? That helps sometimes.