LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 04-24-2012, 04:16 PM   #1
Fritz_Doll
LQ Newbie
 
Registered: Dec 2010
Posts: 20

Rep: Reputation: Disabled
Changing number of pthreads mid run


I would like the option of changing the number of pthreads the program is allowed to run on without killing and rerunning the program.

Is there some mechanism for changing the number of pthreads while the program is mid run?

If so, could you explain how I would do so?
If not, is it at least possible?
General explanations are good enough, but specific would be nice if there isn't a possibility of doing so.

I have a feeling that if I could, it would require serious bookkeeping and a pausing mechanism. A partner program for changing the number of pthreads would also be better than a metafile.

Thanks in advance for any help
 
Old 04-24-2012, 09:39 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
The best way to do it, I think, is to maintain two variables in a central, semaphore-protected table: the limit to the number of threads that you want, and the count of threads that you now have. If this number is increased, then the head-honcho thread simply adds more children. If the number is decreased, the head-honcho signals all the sleeping children to wake up.

Each child (entering the central table one-at-a-time due to the semaphore) notices if the limit is now exceeded. If so, the thread decrements the count and dies. Otherwise, it looks for work-to-do as usual.

In this way, the system will adjust itself in a matter of a few milliseconds to any reduction in the limit. But, no thread is killed: each thread is, as always, an obedient custodian of its own life-span. And, no thread fails to complete whatever unit of work it was in the process of doing at the time that the limit was lowered.
 
  


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
[SOLVED] Changing pattern using sed [number] to number. xpto09 Linux - General 2 06-22-2011 03:32 PM
LXer: Nearly 20% of Mid- and High-end Mobile Devices Will Run a Linux Operating Syste LXer Syndicated Linux News 0 04-22-2008 07:11 AM
Run Puppy via USB mid XP session flotoonie Puppy 2 03-12-2008 12:01 AM
Pthreads + forking to run files flakjacket Linux - Software 2 02-04-2004 02:08 PM
Problem with huge number of pthreads Berng Programming 7 12-17-2003 07:33 AM

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

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

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