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

[K12OSN] Process shared support on RHL




Hello,

I want to know which version of RedHat Linux kernel supports process shared mutex.
If it is not supported as of now,  are there any plans so as to when linux kernel will get this support.


Referring to the site http://pauillac.inria.fr/~xleroy/linuxthreads/faq.html ,  it is known that process shared option is not supported on Linux for LinuxThreads version 0.8 and now LinuxThreads is replaced by NTPL (Native POSIX Threads Library).  But, which version of RedHat Linux has started supporting NTPL?? And also does NTPL support process shared mutex??

Please find a testcase attached to this mail.

The output of this testcase when run on RHL 7.2 and RHL 8.0 is:
./pthr_linux 3
The test starts
LOOP 1
pthread_mutexattr_setpshared failed


Does that mean that RHL 7.2 and RHL 8.0 do not support this (mutex shared across different processes)?? And if yes, is there any workaround to achieve this so as there will not be performance degradation??

The test works on RHL 9.0 as follows:
The test starts
LOOP 1
proc1 lock mutex
proc1 pthread_cond_wait
proc2 locking
proc2 signal waiter  1
ret code of psignal: 0
proc1 is waken up 1
LOOP 2
proc1 lock mutex
proc1 pthread_cond_wait
proc2 locking
proc2 signal waiter  2
ret code of psignal: 0
proc1 is waken up 2
LOOP 3
proc1 lock mutex
proc1 pthread_cond_wait
proc2 locking
proc2 signal waiter  3
ret code of psignal: 0
proc1 is waken up 3
The test end with loop 4


Does that mean process shared mutex is supported on RHL 9.0??

I had posted the query on 25  Jun 2003 but  I did not hear anything.
https://listman.redhat.com/archives/k12osn/2003-June/msg00774.html

Thanking you,
Sayali Surve
#include <sys/ipc.h>  
#include <sys/shm.h>
#if defined(linux)
#include <sys/time.h>
#endif /* linux */
#include <stdio.h>
#include <pthread.h>

/* Usage:
	pthread  loop  yes
		loop: the number of loops the program will run
		yes: print out detail messages
*/


main( int argc, char *argv[] )
{

	int id;
	char *mem;
	pthread_cond_t *p_cond;
	pthread_mutex_t *p_mutex;
	key_t key=0;
	int cnt=0, loop=0, parent_pid=0, child_pid=0;


	if ( argc > 1 )
		loop=atoi(argv[1]);
	else
		printf("Usage: pthread loop yes\n");
        

	printf("The test starts\n");
	parent_pid=getpid();
	key= key + parent_pid;

	while ( cnt++ < loop )
	{

	    key+=200000;

	    printf("LOOP %d  \n", cnt);
	    id=shmget(key, 1024, IPC_CREAT | 0666); 
	    if ( id== -1 )
	    {	printf("shmget failed\n");
		    exit(2);
	    }
	    mem=shmat(id, (char *)0x10000000, 0);
	    if ( mem== (char*)-1 )
	    {	printf("shmat failed\n");
		    exit(2);
	    }

	    p_cond=mem+16;
	    p_mutex=mem+48;

	    /* initialize mutex */
	    {
		pthread_mutexattr_t attr;
	     
		if (pthread_mutexattr_init(&attr))
		    exit(4);
	     
		if (pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED))
		{
		    printf("pthread_mutexattr_setpshared failed\n");
		    pthread_mutexattr_destroy(&attr);
		    exit(5);
		}
		if (pthread_mutex_init(p_mutex, &attr))
		{
		    printf("pthread_mutex_init failed\n");
		    pthread_mutexattr_destroy(&attr);
		    exit(5);
		}
	    }



	    /* initialize cond variable */
	    {
		pthread_condattr_t cvAttr;
	 
		if (pthread_condattr_init(&cvAttr))
		    exit(3);
		
		if (pthread_condattr_setpshared(&cvAttr, PTHREAD_PROCESS_SHARED) ||
		    pthread_cond_init(p_cond, &cvAttr) ||
		    pthread_condattr_destroy(&cvAttr))
		{
		    pthread_condattr_destroy(&cvAttr);
		    exit(6);
		}
	    }


	    if ( (child_pid=fork()) > 0 )
	    {

		printf("proc1 lock mutex\n");
		pthread_mutex_lock(p_mutex);
		sprintf(mem,"aaaaa");

		printf("proc1 pthread_cond_wait\n");
		pthread_cond_wait(p_cond, p_mutex);
		printf("proc1 is waken up %d\n", cnt);

		pthread_mutex_unlock(p_mutex);

		strcpy(mem, "bbbbb");
		waitpid(child_pid,NULL,NULL);
	    }
	    else
	    {
		char cmd[80];
		int err=0, ppid=0, count=0;
		struct timeval tpstart, tpend;

		/* sync, wait for parent process ready */
		while ( mem[0] != 'a'  )
		    sched_yield();
     
		ppid=atoi(mem+1);
		/* wake up parent process */
		printf("proc2 locking\n");
		pthread_mutex_lock(p_mutex);

		printf("proc2 signal waiter  %d\n", cnt);
		err=pthread_cond_signal(p_cond);
		printf("ret code of psignal: %d\n", err);
     
		pthread_mutex_unlock(p_mutex);

		/* check parent process has been waken up */
		gettimeofday(&tpstart,NULL);
                while ( mem[0] != 'b'  )
		{
		    sched_yield();
		    gettimeofday(&tpend,NULL);
		    
		    if ( (tpend.tv_sec - tpstart.tv_sec) > 120 )
		    {
			printf("FAILED, parent process is not waken up, kill parent process\n"); 
			printf("the test failed in loop %d\n", cnt); 
			sprintf(cmd, "kill -9 %d", parent_pid);
			system(cmd);
			exit(1);
		    }
		}
 
		exit(0);
	    }


	    if ( shmdt((char *)0x10000000) != 0 )
	    {	printf("shmdt failed\n");
		    exit(1);
	    }

	    if ( shmctl(id, IPC_RMID, NULL) != 0 )
	    {	printf("ipcrm failed\n");
		    exit(1);
	    }

	}
	printf("The test end with loop %d\n", cnt);
	return(0);
}	


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