⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdthread.c

📁 一个很好的分子动力学程序
💻 C
字号:
/*************************************************************************History*************************************************************************//*23 April 1998A dummy pthread module to replace standard pthread library.  Essentiallywhen this module is included it converts a pthread program to a normal sequential program.The functions do some rudimentary parameter checking to verifythat threads are being called correctly.  This will help catch bugsbefore real threading is used.*//*************************************************************************Compile Switches*************************************************************************//*************************************************************************Include Files*************************************************************************/#include <stdio.h>#include "cdthread.h"/*************************************************************************Defines*************************************************************************/#define BOOLEAN int#define TRUE 1#define FALSE 0#define X 0#define Y 1#define Z 2#define NDIR 3/*************************************************************************Debugging Macros*************************************************************************//*Debugging Macro:  Test assertion, if failed list file and line number*/#define ASSERT(TEST) if (!(TEST)) \	printf ("INTERNAL ERROR: Failed assertion (%s) in file %s line %i.\n", \   #TEST, __FILE__, __LINE__);/*Debugging Macro:  Print current file and line number*/#define WRITEMSG \   { \      printf ("In file %s at line %i.\n", __FILE__, __LINE__); \   }/*Debugging Macro:  Print out variable name and value*/#define WRITEVAR(VAR_NAME,VAR_TYPE) \      { \      printf ("FILE %s LINE %i :", __FILE__, __LINE__); \      printf ("%s = ", #VAR_NAME); \      printf (#VAR_TYPE, (VAR_NAME) ); \      printf ("\n"); \		}/*Debugging Macro:  Print out debugging note*/#define WRITENOT(MSG) \      { \      printf ("FILE %s LINE %i :", __FILE__, __LINE__); \      printf ("  (%s)\n", MSG); \      }/*************************************************************************Macros*************************************************************************/#define LOOP(INDEX,LIMIT) \   for ((INDEX)=0; (INDEX)<(LIMIT); (INDEX)++)/*************************************************************************Type Definitions*************************************************************************/typedef void ThreadFunction_t(void *);/*************************************************************************Global Variables*************************************************************************//*************************************************************************Module-Wide Variables*************************************************************************/static NumProc_m = 1;/*************************************************************************Local Function Prototypes *************************************************************************//*************************************************************************Exported Functions *************************************************************************/void SetNumProc (int NumProc)	{	NumProc_m = NumProc;	}int GetNumProc (void)	{	return NumProc_m;	}/*************************************************************************Exported Functions - PTHREAD LIBRARY REPLACEMENT*************************************************************************//*  Compile this only if not using real threads  */#ifndef USE_THREAD_LIB  int pthread_mutex_init (PTHREAD_MUTEX_T *Lock,PTHREAD_MUTEXATTR_T *Dummy)	{	ASSERT (Lock!=NULL)	*Lock = 0;	}int pthread_create (PTHREAD_T       *Thread, PTHREAD_ATTR_T  *Dummy, void            *(*Function)(void *),void            *FunctionParam)	{	ThreadFunction_t *ThreadFunction;	ASSERT (Function!=NULL)	ASSERT (Thread!=NULL)		ThreadFunction = (ThreadFunction_t *) Function;	ThreadFunction (FunctionParam);	*Thread = 1;	}int pthread_join (PTHREAD_T DummyThread, void *Dummy)	{	DummyThread--;	ASSERT (DummyThread==0)	}int pthread_mutex_lock   (PTHREAD_MUTEX_T *Lock)	{	ASSERT (Lock!=NULL)	ASSERT (*Lock==0)	(*Lock)++;	}int pthread_mutex_unlock (PTHREAD_MUTEX_T *Lock)	{	ASSERT (Lock!=NULL)	ASSERT (*Lock==1)	(*Lock)--;	}#endif   /*  #ifndef USE_THREAD_LIB   *//*************************************************************************Test Driver*************************************************************************/#ifdef TEST_DRIVERvoid  TestFunction (void *);int main ()	{	PTHREAD_T Thread;	pthread_create (&Thread, NULL, (void *) &TestFunction, NULL);	return 0;	}void TestFunction (void *Dummy)	{	printf ("Inside TestFunction\n");	}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -