Pthread problems, 32bit vs 64bit

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Pthread problems, 32bit vs 64bit
# 1  
Old 10-05-2009
Pthread problems, 32bit vs 64bit

I have an application which builds and executes without error on a 32bit implementation of Linux. When I transferred the code to a new project on a 64bit implementation, the code will build without error, but the pthread functions, such as pthread_attr_setschedparam() return an 'Invalid Argument' error. Can anyone shed some light on where I have gone wrong?
# 2  
Old 10-05-2009
Without seeing source code, it is difficult to provide a definitive answer. However, the fact that pthread_attr_setschedparam() is returning EINVAL in 64-bit but works in 32-bit leads me to suspect that one or more of your structures has a programming model dependancy. For example in the IPL32 programming model an int is the same as a long (32 bits) but in an LP64 programming model an int is no longer the same size as a long (an int is 32 bits but a long is 64 bits.)
# 3  
Old 10-05-2009
I have figured out the problem which comes from not totally understanding why I cannot simply call pthread_att_init() to initialize the thread attr data structure, but must call pthread_attr_setschedpolicy(). A snippet of the code follows, the code that failed is highlighted in RED:

err = pthread_attr_init(&thread_attr);
if (err)
fprintf(stderr, "pthread_attr_init() error, %s\n", strerror(err));

thread_param.sched_priority = 2;
err = pthread_attr_setschedparam(&thread_attr, &thread_param);
if (err)
fprintf(stderr, "pthread_attr_setschedparam() error, %s\n", strerror(err));


By adding the lines in BLUE, the code would then operate properly:

err = pthread_attr_init(&thread_attr);
if (err)
fprintf(stderr, "pthread_attr_init() error, %s\n", strerror(err));

err = pthread_attr_setschedpolicy(&thread_attr, SCHED_OTHER);
if (err)
fprintf(stderr, "pthread_attr_setschedpolicy() error, %s\n", strerror(err));


thread_param.sched_priority = 2;
err = pthread_attr_setschedparam(&thread_attr, &thread_param);
if (err)
fprintf(stderr, "pthread_attr_setschedparam() error, %s\n", strerror(err));

Shouldn't the ptread_attr_init() have taken care of the function of pthread_attr_setSchedpolicy() since all elements within the structure should have been set to their default state? In any event, thanks for the help.
# 4  
Old 10-05-2009
According to POSIX.1:2008 the pthread_attr_init() function "shall initialize a thread attributes object attr with the default value for all of the individual attributes used by a given implementation."

However the specification does not specify a specific default value for either schedpolicy or schedparm which means that each implementation of Pthreads chooses some appropriate value. Thus, unless you are aware of the a specific implementation's defaults, if you set one value you should set the other. As a precaution and to ensure my code is portable, I always set both schedpolicy and schedparam if I am adjusting the scheduling policy.

Last edited by fpmurphy; 10-05-2009 at 10:57 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Solaris 10 32bit installation

Hi sorry for the novice question. i need to install Solaris 10 32bit version. i downloaded the ISO from oracle website. as i understand the same ISO is for the 64bit as well as the 32bit install??? i ran the install and didn't have the option to choose which architecture to choose? Thanks... (9 Replies)
Discussion started by: guy3145
9 Replies

2. Shell Programming and Scripting

maintain 32bit and 64bit C code

Hi, I have a C code which builds and works fine on 32bit linux machine. Now i want to convert that code to build and run on 64 bit linux machine. I dont want to maintain two separate sources for 32 and 64 bit build. Same source should get build on 32 as well as 64 bit machine (when a... (2 Replies)
Discussion started by: bhushan123
2 Replies

3. Solaris

Compiler - 32bit or 64bit?

Hi Gurus, I need to check whether the compiler installed in my system supports 64bit compilation. Server - Sun fire v490 OS - Solaris 5.9 Processor - Sparcv9 (64bit) Install Directory - /opt/SUNWSpro Compiler Model - Sun Forte C Compiler. My development team is claiming that there... (20 Replies)
Discussion started by: Hari_Ganesh
20 Replies

4. Solaris

32bit or 64 bit

Not really a Unix question as such :o, but what advantages or disadvantages are there between using 32bit or 64bit applications on a T5220 running Solaris 10? What about mixing them e.g. 64 bit app using 32 bit libraries or vice versa? (1 Reply)
Discussion started by: JerryHone
1 Replies

5. Solaris

32bit / 64bit issue with x86 solaris

i have solaris 10 x86 64bit installed on my pc (dell 3100). i then decided to move my hard drive to another pc (dell 4600). I noticed that each time i boot up, the OS show as 32 bit (instead of 64bit) and i can't even get past this stage to the login page. when i moved it back to dell 3100 it... (13 Replies)
Discussion started by: seyiisq
13 Replies

6. Programming

32bit to 64bit conversion.

Is there an 'easy' way to convert 32Bit code to 64Bit code. I have this benchmark i need to run on different machines and it would be nice if i could run it on the 64 bit machines ass wel. The output when compiling(1) and running(2) are the following: (1) linux:/home/user1/subbench/heapsort #... (7 Replies)
Discussion started by: demuynckr
7 Replies

7. Linux

Linux version v.s. 32bit/64bit

Where can I get a list that maps the each Linux version to corresponding 32/64 bits model? e.g. OS -> Model (ILP32, LP64, ...) RHLE3 -> ? RHLE4 -> ? RHLE5 -> ? ... It would be better if there is such a list that contains most of current UNIX OS versions. ... (1 Reply)
Discussion started by: princelinux
1 Replies

8. Linux

Linux 32bit or 64bit

Hi, I want to know what is command to know which will tell wheather linux is 32 or 64 bit (5 Replies)
Discussion started by: manoj.solaris
5 Replies

9. UNIX for Dummies Questions & Answers

64bit- or 32bit- processor

when using the command : cat /proc/cpuinfo I get some basic info back on the cpu.. but it doesn't tell me if I am using a 64 or 32 bit processor .. a) is this the right command to find this ? b) if it is not what is ? and how do I get that information.. thanx moxxx68 (2 Replies)
Discussion started by: moxxx68
2 Replies

10. UNIX for Dummies Questions & Answers

32bit vs 64bit

Whats the difference between 32bit and 64bit OS's or applications. I understand it a little but its just not clicking the way the teacher explained to me thanks, any info would be much appreciated (1 Reply)
Discussion started by: eloquent99
1 Replies
Login or Register to Ask a Question