HPE GreenLake Administration
- Community Home
 - >
 - Servers and Operating Systems
 - >
 - Operating Systems
 - >
 - Operating System - OpenVMS
 - >
 - pthread_cleanup_push in FORTRAN
 
Operating System - OpenVMS
        1840139
        Members
    
    
        2669
        Online
    
    
        110161
        Solutions
    
Forums
        Categories
Company
Local Language
                
                  
                  back
                
        
                
        
                
        
                
        
        
        
                
        
                
        
        
        
                
        
              
              Forums
Discussions
Forums
- Data Protection and Retention
 - Entry Storage Systems
 - Legacy
 - Midrange and Enterprise Storage
 - Storage Networking
 - HPE Nimble Storage
 
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
                
                  
                  back
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
            
                
            
                
            
                
            
                
            
            
                
            
                
            
            
                
            
                
              
            Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
 - Appliance Servers
 - Alpha Servers
 - BackOffice Products
 - Internet Products
 - HPE 9000 and HPE e3000 Servers
 - Networking
 - Netservers
 - Secure OS Software for Linux
 - Server Management (Insight Manager 7)
 - Windows Server 2003
 - Operating System - Tru64 Unix
 - ProLiant Deployment and Provisioning
 - Linux-Based Community / Regional
 - Microsoft System Center Integration
 
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
        Information
        Community
Resources
Community Language
        Language
        Forums
Blogs
Topic Options
			
				
					
	
			
		
	- Subscribe to RSS Feed
 - Mark Topic as New
 - Mark Topic as Read
 - Float this Topic for Current User
 - Bookmark
 - Subscribe
 - Printer Friendly Page
 
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
08-28-2007 01:31 AM
08-28-2007 01:31 AM
			
				
					
						
							pthread_cleanup_push in FORTRAN
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						Working on Alpha/IA64 V8.3 I have a FORTRAN V8.0 program which creates a thread (to assign some computations to a second cpu) using the pthread library (pthread_create).
Thread creator and thread are both FORTRAN90 subroutines. When the thread is no longer required, the creator calls pthread_cancel.
Before the thread exits it has to release some resources like locked mutexes. For this purpose there is a pthread_cleanup_push function in the pthread interface, but it is implemented as a C macro so cannot be called from a FORTRAN subroutine (guide to POSIX Thread Library, pthread-54).
How can I implement this macro in FORTRAN? Both examples in the documentation are writen in C.
		
		
	
	
	
Thread creator and thread are both FORTRAN90 subroutines. When the thread is no longer required, the creator calls pthread_cancel.
Before the thread exits it has to release some resources like locked mutexes. For this purpose there is a pthread_cleanup_push function in the pthread interface, but it is implemented as a C macro so cannot be called from a FORTRAN subroutine (guide to POSIX Thread Library, pthread-54).
How can I implement this macro in FORTRAN? Both examples in the documentation are writen in C.
		2 REPLIES 2
	
	            
            
		
		
			
            
                - Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
08-28-2007 07:37 AM
08-28-2007 07:37 AM
			
				
					
						
							Re: pthread_cleanup_push in FORTRAN
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						I know nothing, but I'd guess that the easy
way would be to write C wrapper functions
which _could_ use the C macros (in pthread.h
and/or pthread_exception.h). Otherwise, I'd
probably try to draw out what these macros
would get expanded into, and see if it's
practical to re-code the resulting mess in
Fortran. (Looks nasty to me, but I'd assume
that it's possible, at least until I actually
sat down and tried to do it.)
		
		
	
	
	
way would be to write C wrapper functions
which _could_ use the C macros (in pthread.h
and/or pthread_exception.h). Otherwise, I'd
probably try to draw out what these macros
would get expanded into, and see if it's
practical to re-code the resulting mess in
Fortran. (Looks nasty to me, but I'd assume
that it's possible, at least until I actually
sat down and tried to do it.)
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
08-28-2007 11:23 AM
08-28-2007 11:23 AM
			
				
					
						
							Re: pthread_cleanup_push in FORTRAN
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						Michael,
FORTRAN isn't really the best choice of language for playing with threads. Although FORTRAN90 has come a long way, (some would say to turning FORTRAN into PASCAL ;-) there are still quite a few FORTRANish things like static variables and, in some case, argument lists which can make threading very difficult to use reliably. You need to be aware of any reentrancy and sharing of storage. Stack based languages make it all much simpler.
If you can't implement your threading stuff in C, you will need to reimplement the macro in FORTRAN. First locate where the definition comes from (if you have a C compiler, generate a listing with expanded includes and macros), now all you have to do is work out what the macro does! Of course we all know that C code is always readable :-)
		
		
	
	
	
FORTRAN isn't really the best choice of language for playing with threads. Although FORTRAN90 has come a long way, (some would say to turning FORTRAN into PASCAL ;-) there are still quite a few FORTRANish things like static variables and, in some case, argument lists which can make threading very difficult to use reliably. You need to be aware of any reentrancy and sharing of storage. Stack based languages make it all much simpler.
If you can't implement your threading stuff in C, you will need to reimplement the macro in FORTRAN. First locate where the definition comes from (if you have a C compiler, generate a listing with expanded includes and macros), now all you have to do is work out what the macro does! Of course we all know that C code is always readable :-)
	A crucible of informative mistakes
			
			
				
			
			
			
			
			
			
		The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
		
	
	
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP