Skip to content

Commit 23a0643

Browse files
authored
Merge pull request #3631 from facebook/example_streaming_mt
minor : update streaming_compression example
2 parents 1b994cb + 6ec18ae commit 23a0643

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

examples/streaming_compression.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ static void compressFile_orDie(const char* fname, const char* outName, int cLeve
4242
*/
4343
CHECK_ZSTD( ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, cLevel) );
4444
CHECK_ZSTD( ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1) );
45-
ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, nbThreads);
45+
if (nbThreads > 1) {
46+
size_t const r = ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, nbThreads);
47+
if (ZSTD_isError(r)) {
48+
fprintf (stderr, "Note: the linked libzstd library doesn't support multithreading. "
49+
"Reverting to single-thread mode. \n");
50+
}
51+
}
4652

4753
/* This loop read from the input file, compresses that entire chunk,
4854
* and writes all output produced to the output file.
@@ -117,7 +123,7 @@ int main(int argc, const char** argv)
117123
}
118124

119125
int cLevel = 1;
120-
int nbThreads = 4;
126+
int nbThreads = 1;
121127

122128
if (argc >= 3) {
123129
cLevel = atoi (argv[2]);

0 commit comments

Comments
 (0)