Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Semaphore wait and signal!!!!

Semaphore wait and signal!!!!

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tongc
    wrote on last edited by
    #1

    Hi! I've encounter the following problem! Writec pseudo code using semaphore function wait and signal to solve the following problem: A computer system has a pool of N idential printer attached. Processes that wish to print must obtain an available printer. Write two functions: int getPrinter(void); void releasePrinter(int printerID); getPrinter obtains an availble printer from the pool of N printers and return the printer number (0 to N-1) as its result. releasePrinter takes a printer number and makes it available for use by other processes. Here is what i attempt at it #define N //number of printer; int numberOfPrinter = N; int printer[N] //array of N printer; getPrinter(void) { if numberOfPrinter > 0 Then set printer[numberOfPrinter-1] = used return numberOfPrinter-1 else Block } releasePrinter(int printerID) { numberOfPrinter++; set printer[printerID] = not used } Could you please give me any comment or any advise regarding above problem! Thanks

    G 1 Reply Last reply
    0
    • T tongc

      Hi! I've encounter the following problem! Writec pseudo code using semaphore function wait and signal to solve the following problem: A computer system has a pool of N idential printer attached. Processes that wish to print must obtain an available printer. Write two functions: int getPrinter(void); void releasePrinter(int printerID); getPrinter obtains an availble printer from the pool of N printers and return the printer number (0 to N-1) as its result. releasePrinter takes a printer number and makes it available for use by other processes. Here is what i attempt at it #define N //number of printer; int numberOfPrinter = N; int printer[N] //array of N printer; getPrinter(void) { if numberOfPrinter > 0 Then set printer[numberOfPrinter-1] = used return numberOfPrinter-1 else Block } releasePrinter(int printerID) { numberOfPrinter++; set printer[printerID] = not used } Could you please give me any comment or any advise regarding above problem! Thanks

      G Offline
      G Offline
      Gary Wheeler
      wrote on last edited by
      #2

      <no_homework_rant> The purpose of this forum is to help answer programming questions related to Visual C++, not to find people to do your homework for you! </no_homework_rant>


      Software Zen: delete this;

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups