LinuxQuestions.org
Visit Jeremy's Blog.
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 03-23-2005, 10:21 AM   #1
blufire
Member
 
Registered: Jul 2004
Location: Japan
Distribution: Fedora
Posts: 148

Rep: Reputation: 16
semaphores in mutex replacing while loops


Ok two questions in this one.
1. Is it better to use semaphores in a mutex thread program rather than while loops?

I have been looking at some tutorials online and would like a little light shed on the meaning of :
wait(S1);
C--;
if (C < 0) {
signal(S1);
wait(S2);
}
signal(S1);

wait(S1);
C ++;
if (C <= 0)
signal(S2);
else
signal(S1);


I know it has something to do with bool. but do I have to declare S1 or can I declare a different variable for S1 and have it still work?
 
Old 03-23-2005, 12:40 PM   #2
blufire
Member
 
Registered: Jul 2004
Location: Japan
Distribution: Fedora
Posts: 148

Original Poster
Rep: Reputation: 16
I figured out how to work with them and what it all means.

But my program is giving me the following error

/tmp/ccejb4CZ.0(.text+0xcd): In function `main`:
: undefinded reference to `thread_function`
collect2: ld returned 1 exit status

in the beginning of my code I defined it as follows

void *thread_function(void *arg)


I use it in the following line

res = pthread_create(&a_thread, NULL, thread_function, NULL);


and again at the end of my code

int main()
{
}

void *thread_function(void *arg)
{
sem_wait(&bin_sem);
while(strncmp("end", work_area, 3) != 0)
{
printf("You input %d characters\n", strlen(work_area) -1);
sem_wait(&bin_sem);
}

Can someone please explain to me this error?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
semaphores and threads aenasir Programming 0 10-06-2004 09:07 PM
diff. between semaphores/mutex usage on threads skywalker27182 Programming 6 08-16-2004 11:34 PM
What is Semaphores? imsajjadali Red Hat 3 04-23-2004 01:26 AM
Semaphores help mojozoox Programming 1 01-07-2004 08:41 AM
semaphores charles_sjc Linux - Software 2 12-06-2003 12:15 AM

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

All times are GMT -5. The time now is 06:49 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