Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.util.concurrent vs. Boost Threads library

How do the Boost Thread libraries compare against the java.util.concurrent libraries?

Performance is critical and so I would prefer to stay with C++ (although Java is a lot faster these days). Given that I have to code in C++, what libraries exist to make threading easy and less error prone.

I have heard recently that as of JDK 1.5, the Java memory model was changed to fix some concurrency issues. How about C++? The last time I did multithreaded programming in C++ was 3-4 years ago when I used pthreads. Although, I don't wish to use that anymore for a large project. The only other alternative that I know of is Boost Threads. However, I am not sure if it is good. I've heard good things about java.util.concurrent, but nothing yet about Boost threads.

like image 260
user855 Avatar asked Nov 18 '09 20:11

user855


1 Answers

java.util.concurrent and boost threads library have an overlapping functionality, but java.util.concurrent also provide a) higher-level abstractions and b) also lower level functions.

Boost threads provide:

  • Thread (Java: java.util.Thread)
  • Locking (Java: java.lang.Object and java.util.concurrent.locks)
  • Condition Variables (Java. java.lang.Object and java.util.concurrent)
  • Barrier (Java: Barrier)

java.util.concurrent has also:

  • Semaphores
  • Reader-writer locks
  • Concurrent data structures, e.g. a BlockingQueue or a concurrent lock-free hash map.
  • the Executor services as a highly flexible consumer producer system.
  • Atomic operations.

A side note: C++ has currently no memory model. On a different machine the same C++ application may have to deal with a different memory model. This makes portable, concurrent programming in C++ even more tricky.

like image 175
dmeister Avatar answered Nov 15 '22 17:11

dmeister