Is it ever bad practice to use threads?

Hi there ppl,
this may sound like a really silly question is it ever bad practice to use threads? I actually have never explicitly used threads and came across a simple swing application recently which used a thread in the code. Then I started to think that if ever a scenario came up where I was expected to use threads I'd have to learn something new that I should I have already known from birth, then run and hide behind the JAVA API (which is big, real big, BIGGER THAN OPRAH!!!).
So for now I'll "synchronise my watch" (PUN INTENDED), and await the flood of replies.
Thx already ;)

Main Entry: 1pun
Pronunciation: 'p&n
Function: noun
Etymology: perhaps from Italian puntiglio fine point,
quibble -- more at PUNCTILIO
: the usually humorous use of a word in such a
way as to suggest two or more of its meanings or the
meaning of another word similar in sound
emphasis mine (synchronize watch vs. synchronize
threads)...
Ironic that it derives from "fine point, quibble."
¶

Similar Messages

  • Bad practice to assume ordering of columns using *  ??

    I am using Pro*C -- embedded sql
    I have a table with 60 columns and it is partitioned by datetime. It is constantly getting new rows via an array insert, inserting 10 to 100 million rows a day depending on the installation.
    I am currently using select * for the querying.
    I am inserting an array:
    exec sql for :cnt insert into x values (...);
    Is it more efficient or bad practice to assume the ordering of columns. Is it better to list the columns explicitly in the select/insert?
    thanks, lisa

    Yes.
    Imagine if you have added a new column to the table and that column has a default value assigned for older applications (only newer applications will use this added column, old applications should still work), you do not have to re-visit the old application code to change all those insert statements. Only new applications will need to care about what value to put into this newly added column.
    This helps avoid unnecessary changes to existing applications if the new column(s) is added to support new applications only.

  • Hi, I'm designing my 1st website and I started it in  photoshop cs5.5. I know that it's bad practice

    Hi, I'm designing my 1st website and I started it in  photoshop cs5.5. I know that it's bad practice to build with images, I learned this too late. I imported my site into Dreamweaver cs5.5 and uploaded it to my server. The problem I'm having is that I want to apply a jquery drop down menu bar but whenever I try, I get white gaps within my page. How do I convert the coding into a functioning site?*Help Please*  The URL to my site is: http://www.coriemoment.com and this is my coding:
    <html xmlns="http://www.coriemoment.com"
    <head>
    <title>The Official Corie Moment Home</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
        <div id="=container"
    <body bgcolor="#FFFFFF" leftmargin="auto" topmargin="auto" marginwidth="auto" marginheight="auto" margin:0;>
    <!-- Save for Web Slices (home.psd) -->
    <table id="Table_01" width="1281" height="768" border="0" cellpadding="0" cellspacing="0">
              <tr>
                        <td colspan="6">
                                  <img src="images/index_01.png" width="1280" height="220" alt=""></td>
                        <td>
                                  <img src="images/spacer.gif" width="1" height="220" alt=""></td>
              </tr>
              <tr>
                        <td rowspan="4">
                                  <img src="images/index_02.png" alt="" width="414" height="548"></td>
                        <td rowspan="3">
                                  <object width="564" height="423"><param name="movie" value="http://www.youtube.com/v/XbuQiJ6Sv_M?hl=en_US&version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/XbuQiJ6Sv_M?hl=en_US&version=3" type="application/x-shockwave-flash" width="564" height="423" allowscriptaccess="always" allowfullscreen="true"></embed></object></td>
                        <td colspan="3">
                                  <img src="images/index_04.png" width="255" height="89" alt=""></td>
                        <td rowspan="4">
                                  <img src="images/index_05.png" width="46" height="548" alt=""></td>
                        <td>
                                  <img src="images/spacer.gif" width="1" height="89" alt=""></td>
              </tr>
              <tr>
                        <td rowspan="2">
                                  <img src="images/video_03-07.png" width="1" height="336" alt=""></td>
                        <td rowspan="3">
                                  <img src="images/index_07.png" width="34" height="459" alt=""></td>
                        <td>
                                  <script src="http://widgets.twimg.com/j/2/widget.js"></script>
    <script>
    new TWTR.Widget({
      version: 2,
      type: 'search',
      /*put your twitter id that people use to reply to you below. Mine is mhorning. If you only want to see the Tweets that you have Tweeted, then delete the part below that says- OR to:coriemoment */
      search: 'from:coriemoment OR to:coriemoment',
       /*this is the duration in terms of seconds*/
      interval: 30000,
       /*this is the title you want on your tweets*/
      title: 'Corie Tweets',
      subject: 'Send us your comments',
       /*setting width to 'auto' will adjust the width of your tweetbox to whatever is set on your div. You can change this to something like 500px if you want*/
      width: 'auto',
      height: 212,
      theme: {
        shell: {
                 /*this will change the background color of your tweetbox. It is currently yellow*/
                background: 'body p, body img, body embed, body object, body video{opacity:1 !important}',
          /*this will change the color of the text in your background*/
                color: 'fac935'
        tweets: {
                 /*this will change the background color behind your tweets. It is currently white*/
                background: 'body p, body img, body embed, body object, body video{opacity:0.2 !important}',
           /*this will change the color of the text in your tweets. It is currently black*/
                color: '#000000',
           /*this will change the color of anything that is hyperlinked in your tweet. It is currently blue*/
                links: '#1985b5'
      features: {
        scrollbar: false,
        loop: true,
        live: true,
        behavior: 'default'
    }).render().start();
    </script></td>
                        <td>
                                  <img src="images/spacer.gif" width="1" height="302" alt=""></td>
              </tr>
              <tr>
                        <td rowspan="2">
                                  <img src="images/index_09.png" width="220" height="157" alt=""></td>
                        <td>
                                  <img src="images/spacer.gif" width="1" height="34" alt=""></td>
              </tr>
              <tr>
                        <td colspan="2">
                                  <img src="images/index_10.png" width="566" height="123" alt=""></td>
                        <td>
                                  <img src="images/spacer.gif" width="1" height="123" alt=""></td>
              </tr>
    </table>
    <!-- End Save for Web Slices -->
    </body>
    </html>

    mazz2000 wrote:
    The best way to do it is go back to PS and place the navigation area in the design, i would make it 100% of the width and then re-slice the design making sure one single slice is the whole of this navigation area.
    That would be the best way to do it while still using a table layout which in and of itself is not recommended, in large part  for this very reason.
    Every time you want to make a small change to the layout of your site, it will require re-slicing and re-generating code out of PS. You would be much better off taking the time to understand css layouts. Here is a good place to start to get the basics of css: http://www.w3schools.com/css

  • What are the best practices for using the enhancement framework?

    Hello enhancement framework experts,
    Recently, my company upgraded to SAP NW 7.1 EhP6.  This presents us with the capability to use the enhancement framework.
    A couple of senior programmers were asked to deliver a guideline for use of the framework.  They published the following statement:
    "SAP does not guarantee the validity of the enhancement points in future releases/versions. As a result, any implemented enhancement points may require significant work during upgrades. So, enhancement points should essentially be used as an alternative to core modifications, which is a rare scenario.".
    I am looking for confirmation or contradiction to the statement  "SAP does not guarantee the validity of enhancement points in future releases/versions..." .  Is this a true statement for both implicit and explicit enhancement points?
    Is the impact of activated explicit and implicit enhancements much greater to an SAP upgrade than BAdi's and user exits?
    Is there any SAP published guidelines/best practices for use of the enhancement framework?
    Thank you,
    Kimberly
    Edited by: Kimberly Carmack on Aug 11, 2011 5:31 PM

    Found an article that answers this question quite well:
    [How to Get the Most From the Enhancement and Switch Framework as a Customer or Partner - Tips from the Experts|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/c0f0373e-a915-2e10-6e88-d4de0c725ab3]
    Thank you Thomas Weiss!

  • Best practice when using Tangosol with an app server

    Hi,
    I'm wondering what is the best practice when using Tangosol with an app server (Websphere 6.1 in this case). I've been able to set it up using the resource adapter, tried using distributed transactions and it appears to work as expected - I've also been able to see cache data from another app server instance.
    However, it appears that cache data vanishes after a while. I've not yet been able to put my finger on when, but garbage collection is a possibility I've come to suspect.
    Data in the cache survives the removal of the EJB, but somewhere later down the line it appear to vanish. I'm not aware of any expiry settings for the cache that would explain this (to the best of my understanding the default is "no expiry"), so GC came to mind. Would this be the explanation?
    If that would be the explanation, what would be a better way to keep the cache from being subject to GC - to have a "startup class" in the app server that holds on to the cache object, or would there be other ways? Currently the EJB calls getCacheAdapter, so I guess Bad Things may happen when the EJB is removed...
    Best regards,
    /Per

    Hi Gene,
    I found the configuration file embedded in coherence.jar. Am I supposed to replace it and re-package coherence.jar?
    If I put it elsewhere (in the "classpath") - is there a way I can be sure that it has been found by Coherence (like a message in the standard output stream)? My experience with Websphere is that "classpath" is a rather ...vague concept, we use the J2CA adapter which most probably has a different class loader than the EAR that contains the EJB, and I would rather avoid to do a lot of trial/error corrections to a file just to find that it's not actually been used.
    Anyway, at this stage my tests are still focused on distributed transactions/2PC/commit/rollback/recovery, and we're nowhere near 10,000 objects. As a matter of fact, we haven't had more than 1024 objects in these app servers. In the typical scenario where I've seen objects "fade away", there has been only one or two objects in the test data. And they both disappear...
    Still confused,
    /Per

  • Workaround good/bad practice or does it not matter...??

    Hi,
    I have a project that requires other shared actions to hide./show something and was wanting a quick workaround for Hide 1 show 9 so I did as follows..(bear in mind I am using CP7 not 8)
    I copied my hide1 show 20 slide from another project, which retains the connection between buttons and images etc, but as this was too many for my other project, I just set things on the copied slide not to  displlay in output etc adn then renamed the ones I wan to refer to in the new project adn it all works great, however, if wer are doing this is this bad practice as any other CP editor further down the track, needs to edit the project, might think that this is a mess and mish mash with ttoo many objects (although hidden) on the slide and maybe make it more difficult for them.
    My initial thinking on that is while it may look a bit of a mess, My approach to any exising project is to deconstruct it to see exactly what is going on, but some otheres might just look at it as a real pain. (I did it this way as I could not edit a shared action in CP7)
    So, I was just wantig to pose this question to the community and get any feedback on your thoughts about this approach...? (I hope I have explained this correctly and is understandable etc)
    Cheers
    Rossco

    Hi Lilybiri,
    Sorry for the delay in responding.
    I would be interested in your workflow for editing shared actions.
    Hopefully this will be clearer for my explanation of how I initially thought of for editing my shared action...please let me know if this is still not clear.
    I had a Show 1 Hide 20 shared action, using smartshapes as buttons and aside from checkmarks (Ticks) and other images etc.
    I needed to create another similar advanced/shared action, but did not have the time to do so, I needed to just change the existing shared action.
    To do this, I copied the shared action to another project and tried to think of a way I can edit this just by changing the items on the slide. So I tested it out, by selecting a  number of images/buttons and making the ones I did not need, to not be buttons and to not show in output, then just renaming the ones I wanted to show etc...
    And it worked well, so I was happy with that outcome. It may have taken me a while to figure it out initially, but now I know it can be done :-)
    The only negative that some of my colleagues have said, are as follows,with my response back to them.
    Issue: The slide will be a mess as all those items/images are still on it. My response:You can hide the items not used so the slide will not look messy to another CP editor.
    Issue: the images etc will make the file too big and unwieldy My Response: remove the images not needed and the file size will not be a problem.
    Issue: File will be messy for another CP editor to change and take un-necessary time. My Response: Anyone who is a CP user, will/should know how to deconstruct and edit an existing file.
    I hope that makes it clearer :-)
    Cheers
    Rossco

  • Using threads and collecting responses

    Hello,
    I am doing multiple requests to diferent web services from diferent providers. I want to do the requests simultaneously and I think the best way is using threads. I am thinking to create a main class that creates a thread instance for every request (max 5) and then wait for the responses with a timeout. What is best way to implement this? Is there any standard or typical strategy? Different points to consider are:
    - time out, the main class can't wait for ever the threads to end.
    - how every thread passes the response from de web service to the main class.
    Thanks in advance.

    Hi,
    best way to do this may be using an executor service. I cant describe this in detail here..basicly you have to create a executor
    ExecutorService executor = Executors.newCachedThreadPool();then you create so called "Callables" which are like Runnables, but return a result. There you implement your thread functionality in the "call" method.
    public class testCallable implements Callable{
              public Object call() throws Exception {
    }in your controlling class you add these to your executor service and assign the results to a Future (which is a nonblocking operation).
        // make a new Thread for each resouce
              Future[] futures = new Future[5];
              for (int i = 0; i < 5; i++) {
                   futures[i] = executor.submit(new testCallable());
              }then you retrive the result. You can assign a timeout there.
    try {
                 long timeoutTime = System.currentTimeMillis() + timeout;
              for (int i = 0; i < futures.length; i++) {
                   long remainingTime = Math.max(0, timeoutTime
                             - System.currentTimeMillis());
                   try {
                        Result result = (Result) futures.get(
                                  remainingTime, TimeUnit.MILLISECONDS);
    look at
    http://java.sun.com/javase/6/docs/api/java/util/concurrent/ExecutorService.html
    for details
    Greetings
    Brash

  • Is this bad practice?

    Consider the follwing two classes:
    public class Widget
    public class CustomWidget extends Widget
    }Now consider another class that has a Widget class member:
    public class OrdinaryClass
      private Widget w = new Widget();
      public Widget getTheWidget()
        return w;
    }Now suppose I were to subclass OrdinaryClass as follows:
    public class SpecialClass extends OrdinaryClass
      private CustomWidget cw = new CustomWidget();
      public CustomWidget getTheWidget()  // violate LSP?
        return cw;
    }My questions are:
    1) does SpecialClass violate Liskov's Principle in that the getWidget return type has changed?
    2) if it's not in violation, is it bad practice anyway? Or is this some polymorphic trick that is not only acceptable, but very useful (and encouraged)?
    Please advise.

    A custom model was subclassd from AbstractListModel.
    One of the getter methods from ALM has a return of
    f type Object. The custom model used the same
    getter, but returned the toString() of the Object (a
    property) instead of the Object in its entirety.Given this specific class hierarchy, you're into territory for design lawyers. A list mode maintains data that's used by a JList[i/]. The contract, as a result, is fairly open, and you could define the model as maintaining string representations for an object. The purists would respond with "no, the view should decide the representation," and I'd probably agree with them.
    By comparison, the contract for a [i]java.util.List is much more explicit: you put objects into the list, and you get the same objects out. If your colleague was creating a List implementation that returned toString() of an object rather than the object itself, then your argument would have much more force.
    It seems as if changing the return type of a method
    in a subclass seems wrong, even if the new return
    type is a sub of the original return type.
    I have nothing against returning the subclass, mind
    you. Just keep the contract (i.e, the return type)
    the same.However, the "contract" is not defined just by method signature. If that were the case, then this would be a perfectly valid implementation of List.get():
    public Object get(index i)
        return new Integer(i);
    }Instead, the "contract" is defined by the class as a whole, and furthermore is defined by your application for each instance of a class that it creates (eg, "this List is used to pass strings between these two methods").

  • Multi-functional Servlet considered bad practice?

    Hi,
    is it considered bad practice using doGet() for fetching say a blog entry and using doPost() for saving new entries or comments?
    Such as:
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
         blog.getPost(id);
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
         Post post = new Post(title, msg, category, author);
         blog.save(post);
    }I like to think that this is the reasoning or at least part of the reason why doGet and doPost are separate methods.
    Thank you.
    Regards,
    Adam

    Asham wrote:
    Hi,
    is it considered bad practice using doGet() for fetching say a blog entry and using doPost() for saving new entries or comments?Depends on current environment and requirements. In a small hobby application you can do so. In real business I wouldn't do so, it might bite in the future if you plan to extend that servlet with more logic.
    I like to think that this is the reasoning or at least part of the reason why doGet and doPost are separate methods.No, it is not. The HTTP protocol specification (1) offers several request methods, GET, POST, HEAD, PUT, DELETE, etc. The HttpServlet API (2) offers overrideable methods for each of those request methods so that you can handle it using some Java logic. A "plain vanilla" request is always GET. A form submit can be either GET or POST -generally POST is preferred as it can transfer more data and does "hide" query parameters.
    (1) http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
    (2) http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServlet.html

  • Force quitting InDesign as a Matter of Routine. Bad Practice?

    I am trying to convince InDesign users here (CS4, CS5) that using Force Quit as a matter of routine for quitting out of InDesign at the end of the day is a bad practice. I think this started because when we were using K4 (enterprise InCopy/InDesign plug-ins), InDesign DID take a long time to quit because of communication to the K4 database and disconnecting.
    I need some good evidence to convince everyone to quit out of InDesign normally. And also other programs they use. My argument is that when InDesign quits, it updates its preferences and perhaps may even clean something up. Anyone know?

    I work on local files only, and I still have to either leave my desk for 10 minutes after I try to quit then shut down, or force quit and shut down. I do work on some large files though (50-100 meg catalogs) with lots of photos linked in. I guess it takes forever to clear all the cached memory or something. If I try to do a shutdown with InDesign open. I always get a time out error. Also when I go back to InDesign after working in Photoshop, FreeHand, Entourage or FireFox it takes a long time to redraw the InDesign screen and menus.
    I also have a couple of indexing scripts, but don't run them often. Don't see how that would affect anything.
    I read a post somewhere that you could change the "Live Screen Redraw" setting to help with the slowness, but I cannot find that setting in CS3. It may only be in later versions.
    Thanks,
    BJ
    iMac 2.1 GHz PowerPC G5
    Mac OS 10.4.11
    1 GB DDR2 SDRAM (that's wierd, I thought I had 2 GB)

  • Is it bad practice to capture an image that was deployed from mdt after adjustment?

    is it bad practice to capture an image that was deployed from mdt after adjustment?
    or there is no any consequences?
    &quot;When you hit a wrong note it's the next note that makes it good or bad&quot;. Miles Davis

    During years I never captured the image deployed from mdt.
    Today was a rush.
    The request:
    to install time consuming configuration application into the image.
    I restored acronis image that used during couple of weeks for captures after small changes.
    And decided to capture it again before the installation of local progam and final capture.
    It failed after multiple trials. I posted the error yesterday here:
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/a702bf17-8375-4bc7-b458-8ce4894f99e9/error-2147467259-during-capture?forum=mdt
    As a last tip before suggesting to deploy existing image and sysprep it 20 times I deployed the image from MDT applied just Windows KBs and captured again with MDT it worked without any prob.
    So against my usual habit I gave a deployd image for installing the tricky software and then will capture it for future deployment for 20 "special" computers. Feel not so good. But like you told:
    "Will it hurt anything?  Probably not"     I took a chance. In the image no AV, just small things like 7Z and Adobe.
    Encourage me for this case :)
    Thanks.
    &quot;When you hit a wrong note it's the next note that makes it good or bad&quot;. Miles Davis

  • Is it a bad idea to use Task.Delay() in a polling function?

    Is the following a bad idea considering the expense of Task.Delay()?
    async void WatchDog()
    while(!bDisposed)
    //check some things
    await Task.Delay(100);
    Hong

    I've not used the DispatcherTimer, so I can't say anything from experience about how efficient it is or not. The few times I needed this sort of functionality in the few WPF apps I've done, I've used Task.Delay() ... I agree that it is certainly
    a handy option. Most of my polling-type of work has been in non-UI situations (Windows Services), creating my own threading (and using Thread.Sleep()).
    Ah, WinRT ... didn't know that was the platform you're writing for.
    I've got no experience with WinRT. I don't know if there's a separate MSDN forum for that, the only thing I could find was a forum for Surface (https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=surfaceappdevelopment),
    but I don't know if posting questions there would help you or not. Probably the WPF forum would work just as well (https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wpf).
    ~~Bonnie DeWitt [C# MVP]
    http://geek-goddess-bonnie.blogspot.com

  • Catalogue of SQL and PL/SQL bad practices: Call for participation

    I started compiling a list of Oracle SQL and PL/SQL bad practices, with the intention of producing a comprehensive catalogue of common and recurring programming mistakes, that can be used as a check-list for code reviews or given to junior developers. I have identified about 30 bad practices so far. For each bad practice, I provided a list of symptoms in the code, an explanation why it causes problems and a list of preferred solutions.
    My goal with this list is primarily to start a discussion about similar recurring issues that other people have noticed. That discussion should lead to a more complete list which the community will then be able to use, hopefully, to learn something from the mistakes of others and to produce better code.
    I would really appreciate your feedback - if you are interested in discussing these practices we can either do it in this forum, or start a separate mailing list.
    You can download the first version of the catalogue in PDF form from http://gojko.net/effective-oracle
    gojko adzic
    http://gojko.net

    exception handler (already covered), the philosophy
    behind not using stored procedures, and having beenHi riedelme,
    I'm not advocating not using stored procedures, but I am advocating not using exclusively stored procedures. I've seen that approach often, typically with people coming from SQL server or Oracle forms backgrounds, I never could understand the reasons behind it. Even for a simple select or update, they would write a stored proc that wraps the call and then require the client to execute a stored proc.
    I think that views are much better for getting the data out of the database in general, and forcing people to use stored procedures with ref output cursors makes little sense. If the only possible interface is a stored proc, then one proc must be created for every required combination of data and every required filtering or grouping method, so there is much much more code in the database, and more code means harder maintenance.
    If client apps can get data out using views, then they can join them with other views, filter or group the data as they require, which means that there is a lot less code in the database to maintain.
    My other problem with stored-proc only approach is when people wrap simple insert/update/delete commands into a stored proc. Again, I'm not advocating using complex instead-of triggers to implement workflows and forcing people to use views, but I simply don't see any benefit of implementing a stored proc to do a simple update. I see a bad side of it because a stored proc needs to be implemented for every combination of columns that a client may need to update and every criteria that can be used for that. If a client is allowed to update a view, there is much less code in the database.
    Views are, in my experience, also a lot easier to maintain and optimise without downtime because they can be revalidated without causing any problems to currently connected clients, where revalidated stored procedure or package will throw an exception the first time a connected client that had called it before calls it again.
    If I'm missing something, please tell me. I'd really love to understand why someone would build a client API exclusively from stored procedures.
    So far, I've been given explanations that it is for security purposes, or for performance. I don't know of any security restriction that can be implemented on a stored procedure or package that cannot be implemented with a view, and if bound variables and statement caching is used, sql statements don't suffer from sql injection and support pre-compilation.
    Again, i'm not advocating throwing stored procs completely out, i'm against using them exclusively and throwing out any chance of SQL access.
    gojko adzic
    http://gojko.net

  • Using threads in a process of two or more tasks concurrently?

    Dear,
    I need to develop through a Java application in a process that allows the same process using Threads on two or more tasks can be executed concurrently. The goal is to optimize the runtime of a program.
    Then, through a program, display the behavior of a producer and two consumers at runtime!
    Below is the code and problem description.
    Could anyone help me on this issue?
    Sincerely,
    Sérgio Pitta
    The producer-consumer problem
    Known as the problem of limited buffer. The two processes share a common buffer of fixed size. One, the producer puts information into the buffer and the other the consumer to pull off.
    The problem arises when the producer wants to put a new item in the buffer, but it is already full. The solution is to put the producer to sleep and wake it up only when the consumer to remove one or more items. Likewise, if the consumer wants to remove an item from the buffer and realize that it is empty, he will sleep until the producer put something in the buffer and awake.
    To keep track of the number of items in the buffer, we need a variable, "count". If the maximum number of items that may contain the buffer is N, the producer code first checks whether the value of the variable "count" is N. If the producer sleep, otherwise, the producer adds an item and increment the variable "count".
    The consumer code is similar: first checks if the value of the variable "count" is 0. If so, go to sleep if not zero, removes an item and decreases the counter by one. Each case also tests whether the other should be agreed and, if so, awakens. The code for both producer and consumer, is shown in the code below:
    #define N 100                     / * number of posts in the buffer * /
    int count = 0,                     / * number of items in buffer * /
    void producer(void)
    int item;
    while (TRUE) {                    / * number of items in buffer * /
    produce_item item = ()           / * generates the next item * /
    if (count == N) sleep ()           / * if the buffer is full, go to sleep * /
    insert_item (item)                / * put an item in the buffer * /
    count = count + 1                / * increment the count of items in buffer * /
    if (count == 1) wakeup (consumer);      / * buffer empty? * /
    void consumer(void)
    int item;
    while (TRUE) {                    / * repeat forever * /
    if (count == 0) sleep ()           / * if the buffer is full, go to sleep * /
    remove_item item = ()           / * generates the next item * /
    count = count - 1                / * decrement a counter of items in buffer * /
    if (count == N - 1) wakeup (producer)      / * buffer empty? * /
    consume_item (item)      / * print the item * /
    To express system calls such as sleep and wakeup in C, they are shown how to call library routines. They are not part of standard C library, but presumably would be available on any system that actually have those system calls. Procedures "insert_item and remove_item" which are not shown, they register themselves on the insertion and removal of the item buffer.
    Now back to the race condition. It can occur because the variable "count" unfettered access. Could the following scenario occurs: the buffer is empty and the consumer just read the variable "count" to check if its value is 0. In that instant, the scheduler decides to stop running temporarily and the consumer starting to run the producer. The producer inserts an item in the buffer, increment the variable "count" and realizes that its value is now 1. Inferring the value of "count" was 0 and that the consumer should go to bed, the producer calls "wakeup" to wake up the consumer.
    Unfortunately, the consumer is not logically asleep, so the signal is lost to agree. The next time the consumer to run, test the value of "count" previously read by him, shall verify that the value is 0, and sleep. Sooner or later the producer fills the whole buffer and also sleep. Both sleep forever.
    The essence of the problem is that you lose sending a signal to wake up a process that (still) not sleeping. If he were not lost, everything would work. A quick solution is to modify the rules, adding context to a "bit of waiting for the signal to wake up (wakeup waiting bit)." When a signal is sent to wake up a process that is still awake, this bit is turned on. Then, when the process trying to sleep, if the bit waiting for the signal to wake up is on, it will shut down, but the process will remain awake. The bit waiting for the signal to wake up is actually a piggy bank that holds signs of waking.
    Even the bit waiting for the signal to wake the nation have saved in this simple example, it is easy to think of cases with three or more cases in which a bit of waiting for the signal to wake up is insufficient. We could do another improvisation and add a second bit of waiting for the signal to wake up or maybe eight or 32 of them, but in principle, the problem still exists.

    user12284350 wrote:
    Hi!
    Thanks for the feedback!
    I need a program to provide through an interface with the user behavior of a producer and two consumers at runtime, using Threads!So hire somebody to write one.
    Or, if what you really mean is that you need to write such a program, as part of your course work, then write one.
    You can't just dump your requirements here and expect someone to do your work for you though. If this is your assignment, then you need to do it. If you get stuck, ask a specific question about the part that's giving you trouble. "How do I write a producer/consumer program?" is not a valid question.

  • Best practice to use MediaPlayer?

    Is the best practice to use attributes of MediaPlayer (such as playing) or to request the PlayTrait and read its playState attribute?
    (This question comes from a customer.  Reposting here for the OSMF team to respond and for the benefit of the whole group.)
    Sumner Paine
    osmf product manager

    For playback use cases, I'd recommend you stick with MediaPlayer, as it's simpler to use and manages all of the trait event registration.

Maybe you are looking for

  • Why do I have three of every file when I search in finder?

    When I open finder I see three of every file.  I don't  remember seeing this until recently.  Are these duplicates and, if so, how can I delete them without going to every file name?

  • New hard drive replacement on my MacBook Pro.

    I bought a new hard drive for my laptop but I do not have the disc to reboot the new hard drive, can someone help me?

  • Adobe Photoshop CS5 and activations

    Hi everyone...... I have Adobe Photoshop CS5 installed on on Windows XP computer. As I understand, I am allowed 2 activations.  If I first deactivate and then uninstall CS5 on my current computer Will I then get both of my activations back?  I intend

  • Liquidity forecast report question

    Hi, After the expiry of the cash discount period (as per vendor/invoice payment terms), the FF7B (Liquidity forecast) report should show the full invoice amount. In my case, I'm seeing the discounted amount of the vendor invoice and not the full amou

  • Pass Word Access-Remote access

    Having gone thew a few different results for mac results that I can not seem to manage, remote boot logs that came up with a question. Is this a normal Boot Log representing history that is secure?