saturnng/libChf/test03.c

88 lines
1.8 KiB
C
Raw Normal View History

2022-03-21 11:05:59 +01:00
/* $Id: test03.c,v 2.1 2000/05/29 13:10:29 cibrario Rel $
Chf test program.
Generation and signal - single and multithreaded
$Log: test03.c,v $
Revision 2.1 2000/05/29 13:10:29 cibrario
*** empty log message ***
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <setjmp.h>
#ifdef _REENTRANT
# include <pthread.h>
2022-03-21 11:05:59 +01:00
#endif
#define CHF_MODULE_ID 255
2022-03-21 11:05:59 +01:00
#define CHF_EXTENDED_INFO
#include "Chf.h"
void* task( void* arg )
2022-03-21 11:05:59 +01:00
{
const char* msg;
2022-03-21 11:05:59 +01:00
const ChfDescriptor *d, *e;
/* The sleep() is here to increase contention between threads */
sleep( 1 );
2022-03-21 11:05:59 +01:00
printf( "\tThread %d\n", ( int )arg );
2022-03-21 11:05:59 +01:00
/* Generate a condition group and signal it */
ChfCondition 6, CHF_INFO, ( int )arg ChfEnd;
ChfCondition 6, CHF_INFO, ( int )arg ChfEnd;
ChfCondition 6, CHF_INFO, ( int )arg ChfEnd;
ChfCondition 6, CHF_INFO, ( int )arg ChfEnd;
ChfCondition 7, CHF_INFO, ( int )arg ChfEnd;
2022-03-21 11:05:59 +01:00
/* The sleep() is here to increase contention between threads */
sleep( 1 );
2022-03-21 11:05:59 +01:00
ChfSignal();
return ( void* )0;
2022-03-21 11:05:59 +01:00
}
#define N_THREADS 50
2022-03-21 11:05:59 +01:00
int main( int argc, char* argv[] )
2022-03-21 11:05:59 +01:00
{
int st;
int i;
void* ret;
2022-03-21 11:05:59 +01:00
#ifdef _REENTRANT
pthread_t t[ N_THREADS ];
2022-03-21 11:05:59 +01:00
#endif
puts( "test03" );
2022-03-21 11:05:59 +01:00
/* Initialization */
if ( st = ChfMsgcatInit( argv[ 0 ], CHF_DEFAULT, "./test01.cat", 50, 10, 1 ) )
exit( st );
2022-03-21 11:05:59 +01:00
#ifdef _REENTRANT
/* Create */
for ( i = 0; i < N_THREADS; i++ )
if ( pthread_create( &( t[ i ] ), NULL, task, ( void* )i ) ) {
perror( "pthread_create" );
exit( EXIT_FAILURE );
}
2022-03-21 11:05:59 +01:00
/* Join */
for ( i = 0; i < N_THREADS; i++ )
if ( pthread_join( t[ i ], &ret ) ) {
perror( "pthread_join" );
exit( EXIT_FAILURE );
}
2022-03-21 11:05:59 +01:00
#else
task( ( void* )0 );
2022-03-21 11:05:59 +01:00
#endif
/* Exit Chf */
ChfExit();
exit( EXIT_SUCCESS );
2022-03-21 11:05:59 +01:00
}