File: testsems.cpp

package info (click to toggle)
duma 2.5.21-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,460 kB
  • sloc: ansic: 5,512; cpp: 2,205; makefile: 441; javascript: 191; sh: 129
file content (40 lines) | stat: -rw-r--r-- 959 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* Test program for duma. Compile it like this:
g++ foo.cpp -o foo -pthread -ggdb -I /home/andrel/Desktop/duma_2_5_14_x86/ -L /home/andrel/Desktop/duma_2_5_14_x86 -l duma -lpthread
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <new>
#include <dumapp.h>

static void *threadfunc( void *null )
{
	for( int i=0; true; i++ )
	{
		unsigned char *foo = new unsigned char[60];
		if( foo )
		{
			void *copy = foo;
			fprintf(stdout, "%d: before delete of %p\n", pthread_self(), copy);
			fflush(stdout);
			delete[] foo;
			fprintf(stdout, "%d: after  delete of %p\n", pthread_self(), copy);
			fflush(stdout);
		}
	}
}

int main( int argc, char *argv[] )
{
	pthread_t t1, t2, t3;
	pthread_create( &t1, NULL, threadfunc, NULL );
	pthread_create( &t2, NULL, threadfunc, NULL );
	pthread_create( &t3, NULL, threadfunc, NULL );
	pthread_join( t1, NULL );
	pthread_join( t2, NULL );
	pthread_join( t3, NULL );
	return 0;

}