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

 
Output of file : TEST16A.C contained in archive : PCTHREAD.ZIP
/*
* Test16a.c -- Mutex operations with default attributes
*/

#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()
{
static int dummy;
int i, status = 0;

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 default attributes
*/

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

(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 *) &dummy );


/*
* Now, lock the mutex and lower our priority. This will cause the
* system to context switch to the higher priority children each
* of whom will subsequently block when attempting to lock the mutex.
* When all of the children have been dispatched the system will context
* switch to the parent, it will unlock the mutex and the children will
* proceed serially.
*/

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

(void) pcthread_setactive_prio_ns( 1 );
pcthread_mutex_printdata_ns( mutex );

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

return ( status );
}


  3 Responses to “Category : C Source Code
Archive   : PCTHREAD.ZIP
Filename : TEST16A.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/