LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-12-2008, 06:04 AM   #1
acedillo
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Rep: Reputation: 0
semaphores in VMWare and Ubuntu


Hi, I have a c++ code with semaphores that works well if compiled in a Fedora virtual machine over Windows. The same code compiled in the last Ubuntu doesn't work. The sem_wait launch an EINVAL error and doesn't wait for any thread. I've upgraded and downgraded libraries but I get the same result.

example of the code:


//
#include <errno.h>
#include <pthread.h>

int nResult=sem_init(&sem,0,0);
printf("nResult=%d",nResult); //gives 0 (ok)


nResult=sem_wait();
printf("nResult=%d errno=%d\n",nResult,errno); //gives -1 22 (EINVAL)

//

Thx
 
Old 12-12-2008, 11:32 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
I assume you've got an #include <semaphore.h>, and you're passing a pointer to your (successfully initialized) semaphore in to sem_wait ().

In general, "sem_wait()" and friends should work just as well on Ubuntu as any other Linux, and it shouldn't make any difference if you're running as a VM, or using a real, physical host.
 
Old 12-13-2008, 02:22 AM   #3
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
semaphore.h has been removed from the kernel headers since a while back, so the headers versin used to compile glibc will make a difference.
 
Old 12-15-2008, 02:41 AM   #4
acedillo
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Original Poster
Rep: Reputation: 0
So you think semaphores behavior may have changed, don't you?
 
Old 12-15-2008, 09:25 AM   #5
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
I'm not sure that they are supported at all, or it may be that the declarations have been moved to mutex.h. In most places of the kernel, semaphores have been change to mutex's.
 
Old 12-15-2008, 01:03 PM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
acedillo -

I assumed you're writing a user-space program that's using the POSIX "sem_wait()" functions. These are, by definition, completely different from kernel-space semaphores or mutexes.

I'm certain that it doesn't matter if you're using VMWare or a physical host. I'd be surprised if Fedora supported it but Ubuntu doesn't - but, frankly, I haven't checked:

http://www.softwareplug.com/UNIX+7/man/sem_wait/3p
Quote:
The sem_trywait() and sem_wait() functions are part of the Semaphores option and need not be provided on all implementations.
Of course, it's also possible that Posix semaphores are an option on Ubuntu, and you simply need to enable them:
http://manpages.ubuntu.com/manpages/hardy/man4/sem.html

Personally, I've always preferred to use the SysV APIs for stuff like this.

STRONG SUGGESTION:
Check out Beej's Guide to IPC, and see if there are alternatives to Posix semaphores you might not have previously considered ... and might actually prefer:
http://beej.us/guide/bgipc/

Last edited by paulsm4; 12-15-2008 at 01:06 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vmware on ubuntu danfou Linux - Networking 4 12-19-2007 07:25 AM
Ubuntu through VMware mendiratta Ubuntu 8 12-10-2007 09:30 PM
Ubuntu in VMware UltraSoul Ubuntu 2 12-21-2005 11:56 PM
VMware in ubuntu-5.10. greythorne Ubuntu 2 11-24-2005 07:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration