Go to the documentation of this file.00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <vl/generic.h>
00016 #include <vl/random.h>
00017
00018 #include <stdio.h>
00019
00020 #if defined(VL_THREADS_POSIX)
00021 #include <pthread.h>
00022 #endif
00023
00024 #if defined(VL_THREADS_WIN)
00025 #include <Windows.h>
00026 #endif
00027
00028 #if defined(VL_THREADS_POSIX)
00029
00030 void *
00031 testThread(void * args)
00032 {
00033 int j ;
00034 int id = *(int*)args ;
00035 vl_tic() ;
00036 for (j = 0 ; j < 10 ; ++j) {
00037 printf("Thread %5d: %d\n",
00038 id, vl_rand_int31(vl_get_rand())) ;
00039 fflush(stdout) ;
00040 }
00041 printf("Thread %5d: elapsed time: %.2f s\n", id, vl_toc()) ;
00042 return NULL ;
00043 }
00044
00045 #elif defined(VL_THREADS_WIN)
00046
00047 DWORD WINAPI
00048 testThread(LPVOID args)
00049 {
00050 int j ;
00051 int id = *(DWORD*)args ;
00052 vl_tic() ;
00053 for (j = 0 ; j < 10 ; ++j) {
00054 printf("Thread %5d: %d\n",
00055 id, vl_rand_int31(vl_get_rand())) ;
00056 fflush(stdout) ;
00057 }
00058 printf("Thread %5d: elapsed time: %.2f s\n", id, vl_toc()) ;
00059 return 0 ;
00060 }
00061
00062 #endif
00063
00064 int
00065 main(int argc VL_UNUSED, char** argv VL_UNUSED)
00066 {
00067 #ifndef VL_DISABLE_THREADS
00068 #if defined(VL_THREADS_POSIX)
00069 vl_uindex i ;
00070 pthread_t threads [5] ;
00071 int threadIds [5] ;
00072 for (i = 0 ; i < sizeof(threads) / sizeof(threads[0]) ; ++i) {
00073 threadIds [i] = i ;
00074 pthread_create (threads + i, NULL, testThread, threadIds + i) ;
00075 }
00076 for (i = 0 ; i < sizeof(threads) / sizeof(threads[0]) ; ++i) {
00077 pthread_join (threads[i], NULL) ;
00078 }
00079 #elif defined(VL_THREADS_WIN)
00080 int i ;
00081 DWORD threadIds [5] ;
00082 HANDLE threadHandles [5] ;
00083 for (i = 0 ; i < sizeof(threadHandles) / sizeof(threadHandles[0]) ; ++i) {
00084 threadHandles [i] = CreateThread (
00085 NULL, 0,
00086 testThread, threadIds + i,
00087 0, threadIds + i) ;
00088 }
00089 for (i = 0 ; i < sizeof(threadHandles) / sizeof(threadHandles[0]) ; ++i) {
00090 WaitForSingleObject (threadHandles[i], INFINITE);
00091 }
00092 #endif
00093
00094 #else
00095 printf("VLFeat was compiled without threading support\n") ;
00096 #endif
00097 {
00098 char * string = vl_configuration_to_string_copy() ;
00099 printf("%s", string) ;
00100 vl_free(string) ;
00101 }
00102 return 0 ;
00103 }