/home/oan/prosjekt/gotools/segmentation/gpl_distro/lsseg_1.0_gpl/include/simplethreads.h

Go to the documentation of this file.
00001 //===========================================================================
00002 // The Level-Set Segmentation Library (LSSEG)
00003 //
00004 //
00005 // Copyright (C) 2000-2005 SINTEF ICT, Applied Mathematics, Norway.
00006 //
00007 // This program is free software; you can redistribute it and/or          
00008 // modify it under the terms of the GNU General Public License            
00009 // as published by the Free Software Foundation version 2 of the License. 
00010 //
00011 // This program is distributed in the hope that it will be useful,        
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of         
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          
00014 // GNU General Public License for more details.                           
00015 //
00016 // You should have received a copy of the GNU General Public License      
00017 // along with this program; if not, write to the Free Software            
00018 // Foundation, Inc.,                                                      
00019 // 59 Temple Place - Suite 330,                                           
00020 // Boston, MA  02111-1307, USA.                                           
00021 //
00022 // Contact information: e-mail: tor.dokken@sintef.no                      
00023 // SINTEF ICT, Department of Applied Mathematics,                         
00024 // P.O. Box 124 Blindern,                                                 
00025 // 0314 Oslo, Norway.                                                     
00026 // 
00027 //
00028 // Other licenses are also available for this software, notably licenses
00029 // for:
00030 // - Building commercial software.                                        
00031 // - Building software whose source code you wish to keep private.        
00032 //
00033 //===========================================================================
00034 #ifndef THREADSTUFF_H_INCLUDED
00035 
00036 #include <stdio.h>
00037 //#ifdef JON_PTHR
00038 #  include <pthread.h>
00039 //#endif
00040 
00041 #ifndef CRIT_ERR
00042 #  define CRIT_ERR(stmnt) \
00043     printf("\nIn file %s, line %d:\n  ", __FILE__, __LINE__), (stmnt), exit(0)
00044 #endif
00045 
00050 
00051 
00052 //
00053 // The function passed through the first parameter is the function
00054 // actually doing the work, that is, the work of a given 'job'. This
00055 // function is to be supplied by the user.
00056 //
00057 // The function must process the data in the structure pointed to by
00058 // the second parameter, and also return its results as members in
00059 // this structure, or placed wherever this structure's data members
00060 // tells it to.
00061 //
00062 // The function is passed an integer, the id of the job, and a pointer
00063 // to the datastructure belonging to this job.
00064 //
00065 // Typically, that structure contains all the information specific to
00066 // a particular job, and the function will place results in a location
00067 // specified in this structure, which will not be used by any other
00068 // thread.
00069 //
00070 // This means that enough memory for storing the results of all jobs
00071 // must be available when 'do_all_jobs' is called.
00072 //
00073 
00074 // Overview: A number of threads will be started. Each of them will
00075 // look for jobs not done yet, do it, report it done, and go on with
00076 // another job, until all jobs are done. Then the threads are merged,
00077 // and control is returned to the caller of 'do_threaded_jobs'.
00078 
00079 // Note that a seemingly (perhaps) superfluous level of data
00080 // structures is made use of. This is simply to be able to present to
00081 // the user of this library an API in which the user makes a
00082 // 'do_a_job' routine, instead of actually supplying the
00083 // 'do_the_jobs_of_a_thread' routine, thus hiding almost all
00084 // job-server/client, or thread-, specific stuff...
00085 
00086 // A tip: When using this library: Make sure to maintain a
00087 // non-threaded version, it will come in very handy when you need a
00088 // fallback solution for the time when the threaded stuff gets broken,
00089 // and you have no clue as to why!
00090 
00091 //
00092 // 020618: Missing information: Will 'do_a_job' get a pointer to
00093 //         the base of 'job_data_struct_array', or directly to its
00094 //         own member of that list?
00095 //         Same question applies to the output.
00096 //
00097 //         Answer: Seems like both get the base of the array(s).
00098 //         Is this really a good idea?
00099 //
00100 
00101 
00102 
00103 
00104 void do_threaded_jobs(void (*do_a_job)(const int,       // job
00105                                        const int,       // thread
00106                                        void * const,    // input data
00107                                        void * const),   // output data
00108                       void * job_data_struct_array,
00109                       const int threads,
00110                       const int jobs,
00111                       const bool show_progress,
00112                       void * const results);
00113 
00114 
00115 
00116 
00117 
00118 
00119 #define THREADSTUFF_H_INCLUDED
00120 #endif

Generated on Tue Nov 28 18:35:47 2006 for lsseg by  doxygen 1.4.7