0

(1) In a multi-threaded process,If one thread is busy on I/O will the entire process be blocked?

(2) Which is better to use a mutex or a binary semaphore ? When should I use a mutex and when should I use a binary Semaphore ?

SheetJS
  • 22,470
  • 12
  • 65
  • 75
Laavaa
  • 575
  • 9
  • 19

2 Answers2

1

1). Well, at a time only one thread is allocated the CPU in multithreaded application. If you are saying that your thread is regularly busy with I/O, then practically it can happen that all other threads keep waiting in queue to get CPU allocated to them. It depends upon the CPU allocation algorithm used. Like if thread are using Time-Sharing algorithm, then of course on completion of time, current thread will be send to the back of the queue.

2). Check out this post: - Difference between binary semaphore and mutex

Community
  • 1
  • 1
Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
  • @Abhishek.. You're Welcome..If your problem is solved, you can accept it as answer to mark this question resolved.. – Rohit Jain Sep 24 '12 at 17:43
  • 1
    Generally, peforming I/O operations allows other threads that are ready to run to get CPU, (certainly on any OS with a preemptive scheduler, ie. just about all of them). – Martin James Sep 24 '12 at 18:08
  • That also depends upon the priority of the thread busy with I/O operation.. If its priority is high enough, it will not be pre-empted.. – Rohit Jain Sep 24 '12 at 18:11
0

1) In a SMP environment multiple thread can run in parallel(on different cpu). In a single CPU environment, only one thread would be running at a time.

2) read this diff-binary-semaphore-and-mutex

Community
  • 1
  • 1
Harman
  • 1,571
  • 1
  • 19
  • 31