LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-26-2008, 01:34 AM   #1
navderm
Member
 
Registered: Dec 2008
Location: Chandigarh, India
Distribution: Red Hat 9
Posts: 67

Rep: Reputation: 15
Post small enquiry regarding mutex


instead of using mutex

can i not do the following in the function which the thread calls

any_function ()
{
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL);
/* DO WHATEVER YOU WANT TO DO */
pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
}

this way the thread wont get canceled and can perform on a given data. then another thread would start after this thread has finished ??

Please Help..
 
Old 12-26-2008, 02:12 PM   #2
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,549

Rep: Reputation: 180Reputation: 180
Quote:
Originally Posted by navderm View Post
instead of using mutex

can i not do the following in the function which the thread calls

any_function ()
{
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL);
/* DO WHATEVER YOU WANT TO DO */
pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
}
No. Whether or not a thread is cancelable is completely independent of whether or not a thread has exclusive or shared control of some mutex.

------------------
Steve Stites
 
Old 12-26-2008, 07:53 PM   #3
navderm
Member
 
Registered: Dec 2008
Location: Chandigarh, India
Distribution: Red Hat 9
Posts: 67

Original Poster
Rep: Reputation: 15
hello..

Yes that is true indeed. But all I am trying to do here is sync the threads and make sure that a data which is being used by one of the threads is not used by another till the execution of that thread has reached a position where the change in that data won't hamper the execution of previous thread anymore..

Please clarify..
 
Old 12-26-2008, 08:30 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,494

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
Quote:
this way the thread wont get canceled and can perform on a given data. then another thread would start after this thread has finished ??
Cancelling a thread means to terminate it (like killing a process). This is different from context switching where a thread is paused momentarily while the CPU executes a different thread. Cancel state does not affect the context switching between threads. Mutexes do: while a thread is blocked on a mutex it will not run. Threads that are not blocked may run at any time (depends on scheduler).
 
  


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
SpamAssassin enquiry - how to clear the whitelist database bigbadbo Linux - Server 2 12-15-2010 01:35 AM
How to build a distro??? Enquiry only..... shugs81 Linux - Software 3 06-16-2008 06:19 AM
NoobS: Partition Enquiry. Pls advice vandyk Linux - Newbie 4 10-11-2004 09:51 AM
another gtk related enquiry ;-) breakerfall Linux - Newbie 31 06-22-2003 04:31 PM
shell script enquiry chuck77 Linux - General 3 06-12-2003 08:16 AM


All times are GMT -5. The time now is 03:25 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration