Solved

Merging pthreads with X Windows

Posted on 1997-10-21
1
343 Views
Last Modified: 2013-12-26
I am currently developing a multi-threaded C++ apllication on a HP workstation (HP-UX 10.20). The application contains a series of X windows (X11R5) that have been developed using UIM/X. The application receives input data from a variety of external sources. The input is received on a combination of CORBA interfaces, TCP/IP sockets and one serial port. I have set up threads to process the input data, but that data needs to be displayed in the applications windows. Since X11R5 is not thread-safe (and the possibility of being able to upgrade to X11R6 is very unlikely), I need to find a reliable, safe way of getting the application's input data from the various threads that process it into the main "default" thread that contains the X event main loop.

It has been suggested to me that I read the input data into a buffer and then use XSendEvent to generate a X event to pass a pointer to that buffer to a event handler routine for display processing. However, XSendEvent requires a display pointer and window ID, and some of my input will be requests to create a window that does not yet exist. Therefore, I may not always have a window ID to target the X event to.

Another suggestion has been to use UNIX pipes or TCP/IP sockets to pass the pointers to a callback routine to do the display processing. However, I am very unfamiliar with both pipes and sockets, and I am very concerned about error handling and error recovery (i.e. how do I receover if a pipe is broken?).

Therefore, what I am looking for is some information about the benefits and pitfalls of each of these approaches, as well as any suggestions and/or examples of other approaches that I may have not considered.
0
Comment
Question by:EdMosher
1 Comment
 
LVL 2

Accepted Solution

by:
lockhart earned 100 total points
ID: 1295401
The first suggestion is the best. Since all threads can share global memory, just place the display pointer and window id into globals, if they don't exist yet (you'll need to initialize them to NULL) then put your data into another global area and have your X initializer code check it to display the latest data. You'll have to semaphore the global area to make your app thread safe.

Another consideration you might look into is running the X application as a separate process and let the globals reside in shared memory (shmget, etc.) so you don't have to worry about thread safety on the X side.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 85
Separate files macro - Errors on larger data set 18 56
deburging in oracle form 12 76
only14 challenge 19 63
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now