RE: POSIX compliance: pthread_mutex_trylock()

"Liu, Bing Wei" <[email protected]> Tue, 25 Feb 2003 09:57:54 +0800
Newsgroups gmane.linux.ngpt.user
Message-ID <[email protected]>
This issus had been reported and resolved. Please refer to
http://www-124.ibm.com/pipermail/pthreads-users/2003-January/000330.html


----------------------------------------------------------
Bingwei Liu
My words stand for personal point of view

>-----Original Message-----
>From: Selbak, Rolla N [mailto:[email protected]]
>Sent: 2003?2?25? 7:20
>To: '[email protected]'
>Subject: [pthreads-users] POSIX compliance: pthread_mutex_trylock()
>
>
>
>hello,
>
>I am working on the Open POSIX Test Suite project at
>http://posixtest.sourceforge.net
>I ran the POSIX compliance tests upon 
>
>ngpt-2.2.0
>kernel-2.4.18
>glibc-2.2.93-5
>
>There seemed to be an error in the function 
>pthread_mutex_trylock().  The
>test initializes a mutex object (using 
>PTHREAD_MUTEX_INITIALIZER), locks the
>mutex, and then tries to lock the mutex again using 
>pthread_mutex_trylock().
>The expected result is to return an error code of EBUSY, 
>instead it returns
>EDEADLK (35).
>
>The test that I am using to reproduce this issue is part of 
>the POSIX Test
>Suite project http://posixtest.sourceforge.net under
>posixtestsuite/conformance/interfaces/pthread_mutex_trylock/4-1
>.c  (pasted
>the code below)
>
>Error message received was: "Expected 16(EBUSY), got 35"
>
>thanks,
>
>Rolla Selbak
>
>* my views are not necessarily my employer's *
>
>test 4-1.c for pthread_mutex_trylock()
>---------------------------------------
>
>/*   
> * Copyright (c) 2002, Intel Corporation. All rights reserved.
> * Created by:  bing.wei.liu REMOVE-THIS AT intel DOT com
> * This file is licensed under the GPL license.  For the full content
> * of this license, see the COPYING file at the top level of this 
> * source tree.
>
> * Test that pthread_mutex_trylock()
> *   Upon failure, it shall return:
> *   -[EBUSY]   The mutex could not be acquired because it was already
>locked.
>
> * Steps: 
> *   -- Initilize a mutex object
> *   -- Lock the mutex using pthread_mutex_lock()
> *   -- Try to lock the mutex using pthread_mutex_trylock() 
>and expect EBUSY
> *
> */
>
>#include <pthread.h>
>#include <stdio.h>
>#include <errno.h>
>#include "posixtest.h"
>
>pthread_mutex_t    mutex = PTHREAD_MUTEX_INITIALIZER;
>
>int main()
>{
>  	int           	rc;
>
>	if((rc=pthread_mutex_lock(&mutex))!=0) {
>		fprintf(stderr,"Error at pthread_mutex_lock(), 
>rc=%d\n",rc);
>		return PTS_UNRESOLVED;
>	}
>	    		
>   	rc = pthread_mutex_trylock(&mutex);
>      	if(rc!=EBUSY) {
>        	fprintf(stderr,"Expected %d(EBUSY), got %d\n",EBUSY,rc);
>        	printf("Test FAILED\n");
>		return PTS_FAIL;
>      	}
>    	
>    	pthread_mutex_unlock(&mutex);
>  	pthread_mutex_destroy(&mutex);
>
>	printf("Test PASSED\n");
>	return PTS_PASS;
>}
>
>_______________________________________________
>pthreads-users mailing list
>[email protected]
>http://www-124.ibm.com/developerworks/oss/mailman/listinfo/pthr
eads-users