Category : C Source Code
Archive   : PCTHREAD.ZIP
Filename : TEST16B.C

 
Output of file : TEST16B.C contained in archive : PCTHREAD.ZIP
/*
* Test16b.c -- Mutex operations with prio_inherit_c protocol attribute
*/

#include
#include "pcthread.h"

#define LOCK_ATTEMPTS 5
#define THREADS 3

static pcthread_t **lock_th;
static pcthread_mutex_t mutex;
static pcthread_mutexattr_t mu_attr;

static unsigned count = 0;

void
lock( void )
{
while( count < LOCK_ATTEMPTS )
{
pcthread_mutex_lock( (pcthread_mutex_t *) &mutex );
count += 1;
pcthread_mutex_unlock( (pcthread_mutex_t *) &mutex );
}

pcthread_mutex_printdata_ns( mutex );
}

main()
{
int i;

lock_th = (pcthread_t **) malloc( THREADS*sizeof( pcthread_t ));

for(i = 0; i < THREADS; i++ )
lock_th[i] = (pcthread_t *) malloc( sizeof( pcthread_t ));

/*
* Create a mutex with the prio_inherit_c protocol attribute
*/

(void) pcthread_mutexattr_create( (pcthread_mutexattr_t *) &mu_attr );

(void) pcthread_mutexattr_setprotocol( (pcthread_mutexattr_t *)
&mu_attr, prio_inherit_c );

(void) pcthread_mutex_init( (pcthread_mutex_t *)&mutex, mu_attr );

for(i = 0; i < THREADS; i++ )
(void) pcthread_create( lock_th[i],
pcthread_attr_default,
(pcthread_action_t) lock,
(pcthread_addr_t *) 0 );

/*
* Now, lock the mutex and lower our priority.
*/

(void) pcthread_enable_trace_ns();
(void) pcthread_mutex_lock( ( pcthread_mutex_t *) &mutex );

(void) pcthread_setactive_prio_ns( 1 );

(void) pcthread_mutex_unlock( (pcthread_mutex_t *) &mutex );

return (0);
}


  3 Responses to “Category : C Source Code
Archive   : PCTHREAD.ZIP
Filename : TEST16B.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/