xterm_title Test Fix (delay removed)



Proposal for Tomas's xterm_title_restore patch
(possible solution for eliminating ~5-second delay)

This is a test program that illustrates the concept I
mentioned earlier regarding elimination of the 'up to
now' unconditional delay experienced when storing
the xterm_title( re: patch-898 ). If you don't think
introducing a new library dependancy to the package
is a problem, or if you want to kick the code around
a bit before someone takes the time to actually
integrate it with the patch, find any other problem
with the concept/implementation, whatever, let me know
and I or anybody who likes can integrate patch-898
with this code or it's descendants.... (long sentance?
- old habbit from reading Buckminster Fuller...)

To consider:

note on Linux:
#include <pthread.h>

pthread.h:18 -> features.h:312 wants to see a
file "/usr/include/gnu/stubs.h" this may not
exist, and to solve the problem, the Makefile
should test if gnu-path and stubs.h exists,
else: touch /usr/include/gnu/stubs.h

tested on Solaris 8,9, gcc-3.2.1
and RedHat 7.2 (kernel 2.4.17), gcc-3.0.4

for the moment, see first two lines of comment in
the code for the easy build command.

___________________________________________________

/* To build: Solaris: `gcc example.c -lthread -lpthread`           */
/*             Linux: `gcc example.c -lpthread`                    */


/* for testing: lower number here finishes first                   */
/* (not real seconds, but close - for testing only)                */
static int MAX_TIMEOUT = 6;  /* 5 psudo-seconds should be enough   */
static int TITLE_TIME  = 5;  /* this is just for the experiment    */

/* Choose threading model. Solaris threads are POSIX compatible, but
  * this may be needed for backwards compatibility. I found that
  * both Linux and Solaris are compatible with either Posix/nonPosix. */
#define POSIX 1


/* for threading */
#define _REENTRANT
#define NUM_THREADS 2

#ifdef POSIX
#   include <pthread.h>
     pthread_t tid[NUM_THREADS];
#else
#   include <thread.h>
     thread_t tid[NUM_THREADS];
#endif

/* processes */
void spin();
void *child (void *);

/* to exit child threads */
unsigned int quit = 0;

int
main(){

printf("_________________________________________________________________\n");
       printf("\nmain()    Starting a function that will start two
threads"   );
       printf("\n          simultaneously. Whichever one finishes first
will" );
       printf("\n          kill the others and I can continue.\n");
       sleep(2); /* just make the program run smoothly */
       spin(2);  /* this starts the two threads        */
       printf("\nmain()    maha dev!\n");
}

void
spin(int gayatri_mavahayami) /* salute... */
{
   printf("\nspin()    I'm going to start the two threads at very nearly
same time:\n\n");

   int i;

   /*Start threads*/
#ifdef POSIX
     for ( i = 0; i < NUM_THREADS; i++ ) {
       pthread_create(&tid[i], NULL, child, (void *)i );
     }
     for ( i = 0; i < NUM_THREADS; i++)
       pthread_join(tid[i], NULL);
#else   /* Use Solaris */
     for ( i = 0; i < NUM_THREADS; i++ )
       thr_create(NULL, 0, child, (void *)i, 0, &tid[i]);
     while (thr_join(NULL, NULL, NULL) == 0) ;
#endif

   printf("\nspin()    Children done, here do \"return title+3\"...\n");
}

void *
child (void *asamohah) /*sanskrt: 'non-delusion by percieved duality' */
{
   int decide = (int)asamohah;
   int t;
   if (decide == 0) { /* using 0.1 of a second so we exit faster on
success */
     printf("child(%d)  Max_timeout starting...\n",decide);
     for (t = MAX_TIMEOUT*69; t > 0; t--) {
	if (!quit) {
	  usleep(10000);
	} else { t = 0; }
     }
     if (!quit) {
       printf("\nchild(%d)  Max_timeout done first\n",decide);
       printf("          Retrieving title wasn't fast enough, killed
process.\n");
     }
     quit = 1;
   }
   else {
     printf("child(%d)  Get_title   starting... ",decide);
     printf("\n          Here's where I'd get the old_xterm_title...\n");
     int got_it = 0;  /*something for later...*/
     for (t = TITLE_TIME; t > 0; t--) {
	if (!quit) {
	  sleep(1);
	} else { t = 0; }
     }
     if (!quit)
       printf("\nchild(%d)  Got title before timeout, doing away with
twin and self\n",decide);
     quit = 1;
   }
}






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]